Hi,
I have an AS3 Mobile project and i’m having some issues when i try to upload a file, from the camera roll.
The file is uploaded correctly, but the app always throws the error below:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.backendless.service::_FileService/onGetActionStatusResult()[/Users/mark/dev/backendless-git/backendless-sdk-actionscript/src/src/com/backendless/service/_FileService.as:126]
at mx.rpc::Responder/result()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\Responder.as:56]
at mx.rpc::AsyncToken/http://www.adobe.com/2006/flex/mx/internal::applyResult()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\AsyncToken.as:239]
at mx.rpc.events::ResultEvent/http://www.adobe.com/2006/flex/mx/internal::callTokenResponders()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\events\ResultEvent.as:207]
at mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\AbstractOperation.as:244]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:318]
at mx.rpc::Responder/result()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\Responder.as:56]
at mx.rpc::AsyncRequest/acknowledge()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:84]
at NetConnectionMessageResponder/resultHandler()[E:\dev\4.y\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:552]
at mx.messaging::MessageResponder/result()[E:\dev\4.y\frameworks\projects\rpc\src\mx\messaging\MessageResponder.as:235]
Below is the code used to upload the photo from iOS camera roll.
var tempDir:File;
var temp:File;
var cameraRoll:CameraRoll = new CameraRoll();
cameraRoll.addEventListener(MediaEvent.SELECT, imageSelected);
cameraRoll.addEventListener(Event.CANCEL, browseCanceled);
cameraRoll.addEventListener(ErrorEvent.ERROR, mediaError);
cameraRoll.browseForImage();
protected function imageSelected(event:MediaEvent):void
{
var imagePromise:MediaPromise = event.data;
dataSource = imagePromise.open();
var eventSource:IEventDispatcher = dataSource as IEventDispatcher;
eventSource.addEventListener(Event.COMPLETE, onMediaLoaded);
}
private function onMediaLoaded(event:Event):void
{
var imageBytes:ByteArray = new ByteArray();
dataSource.readBytes(imageBytes);
tempDir = File.createTempDirectory();
var now:Date = new Date();
var filename:String = "IMG" + now.fullYear + now.month + now.day + now.hours + now.minutes + now.seconds + ".jpg";
temp = tempDir.resolvePath(filename);
var stream:FileStream = new FileStream();
stream.open(temp, FileMode.WRITE);
stream.writeBytes(imageBytes);
stream.close();
temp.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, uploadCompleteHandler );
temp.addEventListener(IOErrorEvent.IO_ERROR, ioError);
try
{
Backendless.FileService.upload(temp, "userPictures");
}
catch( e:Error )
{
trace("TryCatch error: " + e);
}
}
protected function uploadCompleteHandler(event:DataEvent):void
{
trace("uploadCompleteHandler -> url: " + event.data);
}
protected function mediaError(event:ErrorEvent):void
{
trace(“mediaError”);
}
protected function browseCanceled(event:Event):void
{
trace("browseCanceled");
}
protected function ioError(event:IOErrorEvent):void
{
trace(“ioError”);
}