Skip to content

support of base64 string in S3Adapter #600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mchun opened this issue Feb 23, 2016 · 10 comments
Closed

support of base64 string in S3Adapter #600

mchun opened this issue Feb 23, 2016 · 10 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@mchun
Copy link

mchun commented Feb 23, 2016

In the current file adapter of api.parse.com, I can see that both file and base64 string are supported.

e.g. data = {"_ContentType":"image/jpeg","base64":"/9j/4AAQSkZJRgABAQAAAQ..........."}
and also
data = $("#ulPhoto1")[0].files[0];

I do rely on this a lot when performing client-side resize image function.
Can we do the same in the S3Adapter?

P.S. This is the code I used to upload image.

$.ajax({
      type: "POST",
      beforeSend: function(request) {
        request.setRequestHeader("X-Parse-Application-Id", 'myAppId');
        request.setRequestHeader("X-Parse-REST-API-Key", 'myRestAPIKey');
        request.setRequestHeader("Content-Type", "image/jpeg");
      },
      url: "http://localhost:1337/parse/files/photo.jpg",
      data: data,
      processData: false,
      contentType: false,
      success: function(photo) {
           ......
      },
      error: function(jqXHR, textStatus, errorThrown)  {
           ......
      }
    });
@tanmays
Copy link

tanmays commented Feb 23, 2016

What's the error that you get? If its request entity too large then its the same as #536

@mchun
Copy link
Author

mchun commented Feb 23, 2016

I did not face any error, but the image uploaded on S3 is simply unreadable.

@flovilmart
Copy link
Contributor

@mchun does it work with Parse.File().save() ?

@mchun
Copy link
Author

mchun commented Feb 24, 2016

It works with Parse.File("photo.jpg", { base64 : data }). But it would be great if it can be done via REST api too.

@flovilmart
Copy link
Contributor

ok, that's good to know, Did you try with the latest 'master"?

@mchun
Copy link
Author

mchun commented Feb 25, 2016

Just tried with 2.1.3 and the problem still exists.

@flovilmart
Copy link
Contributor

I'll have a look

@flovilmart flovilmart added the type:bug Impaired feature or lacking behavior that is likely assumed label Feb 25, 2016
@flovilmart
Copy link
Contributor

@mchun we fixed a few things with the content type in recent releases, and I just checked, the base64 is properly restored as a buffer in the early middlewares.
Please retry on 2.1.6 and I'll reopen if needed.

@mchun
Copy link
Author

mchun commented Mar 13, 2016

I have just tried 2.1.6, but sadly it is still not working...
When using the Parse hosted server, the following works without problem:

    $.ajax({
      type: "POST",
      beforeSend: function(request) {
        request.setRequestHeader("X-Parse-Application-Id", 'myAppId');
        request.setRequestHeader("X-Parse-REST-API-Key", 'myRestAPIKey');
        request.setRequestHeader("Content-Type", "image/jpeg");
      },
      url: serverUrl,
      data: data,
      processData: false,
      contentType: false,
      success: function(photo) {...}
  });

where data is the following..(unlike what I described in the original post, my bad)

var data = JSON.stringify({
            '_ContentType':"image/jpeg",
            'base64': "/9j/4AAQSkZJRgABAQAAAQ..........."
          });

I have tried many thing, like removing "_" of ContentType inside data, changing the contentType of $.ajax to "image/jpeg", not stringifying the object....etc, but nothing works. Did I do anything wrongly?

The file can be save successfully but it is not viewable. i.e.,
https://freesthdebugclone.s3.amazonaws.com/8d4102158737ee2111bdef5d5d3667e8_1.jpg

@joshuamshana
Copy link

I try to save base64 file using REST, it seems not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

4 participants