0

I used the apache royal 0.9.7 stable to implement a feature to display pdf from server.

Here is a sample code:

var byteCharacters:String = unescape(encodeURIComponent(pdfData));
var byteNumbers:Array = new Array(byteCharacters.length);

for (var i:int = 0; i < byteCharacters.length; i++) {
    byteNumbers[i] = byteCharacters.charCodeAt(i);
}

var byteArray:Uint8Array = new Uint8Array(byteNumbers);
var file:Blob = new Blob([byteArray], {type: 'application/pdf'} as
BlobPropertyBag);
var fileUrl:String = URL.createObjectURL(file);

window.open(fileUrl);   

When trying to view the pdf file, I get this error in console: ReferenceError: BlobPropertyBag is not defined

I saw same issue on https://github.com/apache/royale-compiler/issues/81, then I tried the nightly 0.9.8, but I still have the same issue.

Can anyone help why the dependency is not found ?

Hadi
  • 1
  • 1

1 Answers1

0

For what I see in framework code (i.e: org.apache.royale.storage.providers.WebStorageProvider, the use is:

COMPILE::JS {
var blob:Blob = new Blob([text], new BlobPlainTextOptions());
fileWriter.write(blob);
}

... and in the same file add a helper class ...

COMPILE::JS
class BlobPlainTextOptions implements BlobPropertyBag
{
    public function get type():String
    {
        return "text/plain";
    }
    
    public function set type(value:String):void
    {
        
    }
}
Carlos Rovira
  • 507
  • 2
  • 11
  • When I add the helper class in the same file, it does not compile, saying nested class is not allow. I then created a class file, but I get this error: `Bad dependency path or symbol: BlobPropertyBag` – Hadi Aug 27 '20 at 12:49
  • Probably you're adding the class inside the package, but must me outside. The best is you check how is done in the framework code and compare with your code to see differences. There are some cases. for examples check this: https://github.com/apache/royale-asjs/blob/7ac975f376dbcbd7d27c56a83528dfd72830aba1/frameworks/projects/Storage/src/main/royale/org/apache/royale/storage/providers/WebStorageProvider.as#L202 – Carlos Rovira Aug 28 '20 at 13:38