PhantomAppDevelopment / firebase-as3

Integrate Firebase Auth, Realtime Database and Storage in your Adobe AIR projects.
MIT License
55 stars 12 forks source link

error request uploading file with progress #13

Closed benkhachouch closed 7 years ago

benkhachouch commented 7 years ago

hello,

Thanks for your tutorial.Very usefull. i can upload file (without progress event) but i have a error ("bad request") when i want to upload file.with progress event.

Please where is my fault? public static function uploadFileVideo(authToken:String,url,file:File):void { var header:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer " + authToken); var request:URLRequest = new URLRequest(Constants.FIREBASE_STORAGE_URL +url) request.requestHeaders.push(header); file.addEventListener(ProgressEvent.PROGRESS, progressHandler); file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, uploadCompleteDataHandler);

        var fileStream:FileStream = new FileStream();
        fileStream.open(file, FileMode.READ);

        var bytes:ByteArray = new ByteArray();
        fileStream.readBytes(bytes);
        fileStream.close();

       // var request:URLRequest = new URLRequest(url)
        request.method = URLRequestMethod.POST;
        request.data = bytes.toString();
        request.contentType = "application/octet-stream";

        file.uploadUnencoded(request);

    }
agentphantom commented 7 years ago

I believe you only need to add the following lines:

var header:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+authToken);           

//Then in the request body
request.requestHeaders.push(header);