Skip to content
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

Interface ImgCropperConfig output - more detail in docs #98

Open
jmpreston opened this issue Oct 19, 2019 · 9 comments
Open

Interface ImgCropperConfig output - more detail in docs #98

jmpreston opened this issue Oct 19, 2019 · 9 comments
Labels

Comments

@jmpreston
Copy link

🪲 Bug report

I'm trying to figure out how to get a jpg file instead of base64 as the Output for the image cropper. The output config looks interesting for that but I need more explained how it is used.

@Enlcxx
Copy link
Member

Enlcxx commented Oct 22, 2019

You can't get a jpg image, maybe we could get a blob.
For now it is only possible to obtain the image in base64, would it be fine if the result were in blob?

@Enlcxx Enlcxx added the docs label Oct 22, 2019
@jmpreston
Copy link
Author

Well, I've spent days trying to figure out how to convert a blob into a jpg and have an open Stack Overflow issue on that posted yesterday. I've never worked with any of this before so I'm lost on this part. Your cropper is very good! I just can't figure out what to do with a dataURL. I could post it to my db but images don't belong in a db, only a reference to them. So rather stuck. It would be good if the docs helped us who were new to working with images.

@Enlcxx
Copy link
Member

Enlcxx commented Oct 22, 2019

What database are you using?

@Enlcxx
Copy link
Member

Enlcxx commented Oct 22, 2019

For example I am using Firebase Storage, this accepts files from File, Blob and base64, even an array of bytes.

@jmpreston
Copy link
Author

jmpreston commented Oct 22, 2019 via email

@jmpreston
Copy link
Author

jmpreston commented Oct 22, 2019 via email

@Enlcxx
Copy link
Member

Enlcxx commented Oct 23, 2019

I think you should convert base64 to a File object, a File object is equal to the e.target.files[0] of a

e.g.

const file = dataURLtoFile(e.dataURL, e.name);
var upload = new AWS.S3.ManagedUpload({
    params: {
      Bucket: albumBucketName,
      Key: photoKey,
      Body: file,
      ACL: "public-read"
    }
  });

// from https://stackoverflow.com/questions/35940290/how-to-convert-base64-string-to-javascript-file-object-like-as-from-file-input-f
function dataURLtoFile(dataurl: string, filename: string) {
    var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
        bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
    while(n--){
        u8arr[n] = bstr.charCodeAt(n);
    }
    return new File([u8arr], filename, {type:mime});
}

@jmpreston
Copy link
Author

jmpreston commented Oct 23, 2019 via email

@Enlcxx
Copy link
Member

Enlcxx commented Oct 23, 2019

I don't understand that from a binary jpg. The cropped image has to be uploaded to a server, once uploaded, you can get the url to use it in the template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants