piotrzarzycki21 commented on issue #1251:
URL: https://github.com/apache/royale-asjs/issues/1251#issuecomment-2577246132
@sanjeev-rajput here are what we are doing in our app to upload file
Step 1:
In our view we are declaring following beads:
```
<fx:Declarations>
<js:FileProxy localId="fileProxyUpload">
<js:beads>
<js:FileBrowserWithFilter localId="fileBrowser"
filter=".yourfileextension"/>
<js:FileModelWithParams localId="fileModel" />
<js:FileLoader localId="fileLoader"/>
<js:FileUploaderWithResponseData
id="fileUploader" contentType=""/>
</js:beads>
</js:FileProxy>
</fx:Declarations>
```
In the background FileUploaderWithResponseData is doing what you are
searching for:
https://github.com/apache/royale-asjs/blob/36265208992aea285ca3e7809afd546512065285/frameworks/projects/Network/src/main/royale/org/apache/royale/file/beads/FileUploader.as#L83
Step 2: Register on event "modelChanged" using fileProxyPload
```
fileProxyUpload.addEventListener("modelChanged", onFileModelChanged);
private function onFileModelChanged(event:Event):void
{
fileModel.addEventListener("blobChanged", onFileBlobChanged);
fileLoader.load();
}
private function onFileBlobChanged(event:Event):void
{
fileModel.removeEventListener("blobChanged", onFileBlobChanged);
//fileModel.name; - You can store somewhere if you need your file name
}
```
Step 3:
We have Button where on click we do browse. It opens for you window to
pickup the file.
```
private function onButtonClick(event:MouseEvent):void
{
fileBrowser.browse();
}
```
Step 4:
We have button called "Upload" - where you basically starting submitting
your data to your server side or wherever you want
```
private function onFormSubmitClick(event:MouseEvent):void
{
// to-do
// do validation check here
if (!fileModel.blob)
{
view.uploadFileResult("Please attach an .id file to continue.");
return;
}
//fileModel.setParam("fileparam", "yourparams")
fileUploader.upload("serverurl");
}
```
Note that we have special bead which extends FileUploaderWithResponseData -
I will add that bead to Royale so other could benefit. What we do in this
extension is we are sets to true `xmlHttpRequest.withCredentials = true;`
I hope this helps.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]