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

Allow data-url image upload using file input (from Infragram) #6594

Closed
jywarren opened this issue Nov 1, 2019 · 1 comment · Fixed by #6930
Closed

Allow data-url image upload using file input (from Infragram) #6594

jywarren opened this issue Nov 1, 2019 · 1 comment · Fixed by #6930
Assignees

Comments

@jywarren
Copy link
Member

jywarren commented Nov 1, 2019

This is a project I'm working on to allow Infragram images to be posted to PublicLab.org easily. They are, for better or worse, data-urls. So i want to make a JS call or a URL that opens https://publiclab.org/post with some parameters (GET or POST) that then make the editor open with the image already set as the lead image.

https://stackoverflow.com/questions/4998908/convert-data-uri-to-file-then-append-to-formdata

I think we can use this to intercept the data-url (in a POST because GET can't accommodate long data-uris) and then set the main image input to that. It's a stretch but i think it could work.

This failed: https://stable.publiclab.org/post?main_image=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8%2F9hAAAAAklEQVR4AewaftIAAAApSURBVKXBAQEAAAiAIPP%2F5mqEMAtHIJFEEkkkkUQSSSSRRBJJJJFEEj1UXgIdx5M8pQAAAABJRU5ErkJggg%3D%3D

(as a first attempt)

@jywarren jywarren self-assigned this Nov 1, 2019
@jywarren
Copy link
Member Author

jywarren commented Dec 6, 2019

OK, this works from image-sequencer, but is not accepted by plots2, which needs an exception for protect_from_forgery based on the domain name of origin!

function postToPL(imgSrc) {
  var uniq = Date.now();
  $('body').append('<form method="post" id="postToPL' + uniq + '" action="https://publiclab.org/post" target="postToPLWindow"><input type="hidden" name="datauri_main_image" /></form>');
  f = $('#postToPL' + uniq)[0];
  f.datauri_main_image.value = imgSrc;
  window.open('', 'postToPLWindow');
  f.submit();
}
postToPL($('img')[0].src)

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

Successfully merging a pull request may close this issue.

1 participant