Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1172] Android HTTPClient: POST with image encoded as base64 sent as GET

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionCannot Reproduce
Resolution Date2016-01-07T08:24:05.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsandroid, defect, httpclient
ReporterRyan Asleson
AssigneeSharif AbuDarda
Created2015-12-25T21:18:01.000+0000
Updated2016-03-08T07:37:32.000+0000

Description

Attachments

FileDateSize
IMAG0443.jpg2015-12-25T20:59:56.000+00001886092
post-as-base64.txt2015-12-25T21:05:13.000+00002647930
post-as-binary.txt2015-12-25T21:01:58.000+00003228034
post-with-both.txt2015-12-30T22:38:50.000+00005742965

Comments

  1. Sharif AbuDarda 2015-12-30

    What happens when you keep both of them?
           var data = {
       
               "entry.id": entryBean.id
       
               , "_eventName": "uploadPhoto"
       
               , "imageData": selectedImage
       
               , encodedImage: Ti.Utils.base64encode(selectedImage).toString()
       
               , "caption": $.caption.value
       
               , "fileName": getFileNameFrom(selectedImage)
       
           };
       
    Or try to make a blob of the image and then try base64encode.
       image=selectedImage.toBlob(); 
       ...
       encodedImage: Ti.Utils.base64encode(image).toString()
       
    Reply with your response. Thanks.
  2. Ryan Asleson 2015-12-30

    First, I noticed that the encodedImage key on the data object wasn't in quotes like the others, so I changed it. Doesn't seem to have made a difference. Anyway, when I sent the image as both binary data and as base64 like this:
           var data = {
               "entry.id": entryBean.id
               , "_eventName": "uploadPhoto"
               , "imageData": selectedImage
               , "encodedImage": Ti.Utils.base64encode(selectedImage).toString()
               , "caption": $.caption.value
               , "fileName": getFileNameFrom(selectedImage)
           };
       
    The data was correctly sent as a POST. See attachment post-as-both.txt. When I tried your suggestion of converting to a blob like this:
        
       var data = {
               "entry.id": entryBean.id
               , "_eventName": "uploadPhoto"
               , "imageData": selectedImage
               //, "encodedImage": Ti.Utils.base64encode(selectedImage).toString()
               , "encodedImage": Ti.Utils.base64encode(selectedImage.toBlob()).toString()
               , "caption": $.caption.value
               , "fileName": getFileNameFrom(selectedImage)
           };
       
    I get a runtime error that says this: Message: Uncaught TypeError: Object [object TiBlob] has no method 'toBlob' Source: encodedImage: TiUtils.base64encode(selectedImage.toBlob()).toStri Apparently selectedImage is already a Blob. Does that help?
  3. Sharif AbuDarda 2016-01-07

    Hello, It looks like when you tried to sent the image as both binary data and as base64, The data was correctly sent as a POST. Which I think resolves your issue. We will resolve this issue. If you have any further requirement please let us know. Thanks.
  4. Ryan Asleson 2016-01-08

    Hi, it's definitely *NOT* working correctly. The problem is that when sending the image as base64 (and only base64), the data is sent as a GET instead of a POST. See attachment post-as-base64.txt. My apologies, but I should have mentioned earlier that I do explicitly set the request to be a POST:
           var data = {
               "entry.id": entryBean.id
               , "_eventName": "uploadPhoto"
               , "imageData": selectedImage
               // , encodedImage: Ti.Utils.base64encode(selectedImage).toString()
               , "caption": $.caption.value
               , "fileName": getFileNameFrom(selectedImage)
           };
           
           var options = http.standardOptions();
           options.url = "mobile/entry/EntryImage.action?_eventName=uploadPhoto";
           options.method = "POST";
           options.data = data;
           options.onComplete = function(response) {
               Ti.API.info("made it to PhotoUpload onComplete!!!!");
               onUploadComplete(response);
           };
           options.onLoginSuccess = closeWindow;
               
           http.send(options);
       
    Yes, when I sent the image as both binary and base64 the request was correctly sent as a POST. The issue is that when the image is sent *only* as base64, it's sent as a GET. Let me know what you find. Thank you!!!

JSON Source