File Upload error

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”);

	}

Hi Eric,

Would it be possible for you to check with Charles what the server returns as a result of the upload and post screenshots here?

Regards,
Mark

Hi Mark. Sure, it’s possible, but who is Charles and how do I contact him?

As i said, the file is indeed uploaded to the server, and i can event get the URL on the uploadCompleteHandler, but about 2 seconds later FlashBuilder throws that error.

Hi Eric,

Charles is a debug proxy utility. You can download it from: http://www.charlesproxy.com/

If you run the app on a device, you will need to configure it to point to the Charles proxy: http://www.charlesproxy.com/documentation/faqs/using-charles-from-an-iphone/

Once configured and when you make a request, Charles will show the on-the-wire traffic between the app and our servers.

Before you run the app, you will need to make the following change in your code. Before you call Backendless.initApp(), do the following:

Backendless.SITE_URL = “http://api.backendless.com/”;

This is needed to change the protocol to http:// (it is https:// by default and as a result, the traffic will be encrypted without that change).

Regards,
Mark

Wow, now i’m feeling stupid thinking that Charles was a person, LOL.

Well, here are some screenshots.

I run the app another time because i forgot to send pictures from other entry that showed on Charles.

Thanks, Eric. Don’t feel bad about not knowing what Charles is. It is a great tool with a not very common name for a software product :wink:

I think I know what the issue is with the file upload. We’ll work on it and post a patch for the SDK.

Regards,
Mark

Thanks again Mark!

Hi Eric,

I was checking with the latest build of SDK for ActionScript (the one on the website) and I cannot reproduce the problem. How long ago did you download the SDK?

Regards,
Mark

I downloaded less than a month ago.

Here’s a link to a sample project i’ve just created, to illustrate that error.

http://goo.gl/9MalxX

The latest release was on July 4th:
https://backendless.com/backend-as-a-service/release-history/

Just to be absolutely sure, could you try grabbing the latest SDK, replace backendless.swc in your project and try again? (make sure to delete the app from the phone before you redeploy).

Regards,
Mark

Hi Mark, that is the version i am using. I’ve uploaded the project so you could test it too, the link is in the last post.

Here’s a link toa video i’ve just made recording the error. I am testing in the iOS simulator.

http://goo.gl/rFCOmL

Could you please try it with the library attached to this response?

Regards,
Mark

backendless.swc.zip (0.92MB)

Hi Mark, i testes with the new SWC and got the same error, but this time i also got a new log on the console, that says “got result - null”, before the error.

I’m sending a screenshot.

Hi Eric,

This is quite strange. Please take a look at the attached screenshot. It shows a call the app should make. Based on the errors you reported, that call somehow is failing for you. Could you please run with Charles again and check if you see that call and what the AMF Response shows for it?

Also, when I run your code, I get the following error with the iOS emulator:

[trace] Error #2044: Unhandled ErrorEvent:. text=Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful.
[trace] at Foo/init()[/Users/mark/dev/backendless/projects/Uploader/src/PictureUpload.as:39]

Line 39 contains this code:
var cameraRoll:CameraRoll = new CameraRoll();

Any ideas what this might be?

Regards,
Mark

Now, for no apparent reason, my code isn’t working. I got error on the File.system api on Flash Builder.

Error: Error #0

at flash.filesystem::FileStream/writeBytes()

at PictureUpload/onMediaLoaded()[/Users/eric/Estudos/Backendless-AS3/PictureUpload/src/PictureUpload.as:64]

I didn’t change a thing since yesterday and today it’s not even sending the file. There’s something wrong with Flash Builder or the simulator.

I’ll do more tests to see if i find something.

Thanks!

Hi Eric,

I was able to reproduce the problem and have fixed it. Please try with the attached library (as soon as you get that other issue resolved). Let me know if it works for you.

Regards,
Mark

backendless.swc.zip (0.92MB)

Congratulations Mark, now it’s working!!! Thank you very much.

Will you upload this version to github?

Thanks again!

Hi Eric,

Yes, it is already in github and on our site:

https://backendless.com/downloads/
https://backendless.com/backend-as-a-service/release-history/

Cheers,
Mark