0

Can anyone help me to get file-input object from image url

Sample image url :

https://image.shutterstock.com/image-photo/bright-spring-view-cameo-island-260nw-1048185397.jpg

Can anyone help me to get file object

By file object i mean the below format

enter image description here

Any fiddle will be highly thankful

Always Helping
  • 14,316
  • 4
  • 13
  • 29
midhun k
  • 546
  • 1
  • 12
  • 28
  • Not possible, because the server doesn't send along that information, afaik. You can only get that for files the user selects in the context of a `` –  Jul 16 '20 at 07:04
  • @ChrisG i do have image url only handy and backend is expecting the file object . Am not uploading , already uploaded file with url only – midhun k Jul 16 '20 at 07:12
  • or else is it possible to get fileinput object from base64 object . i can convert url to base64 , from there to file object . is there any way @ChrisG – midhun k Jul 16 '20 at 07:14
  • I guess you're trying to upload the image to your own backend? You should be able to create a Blob from the image and insert that into a FormData object. Note that if this is what you're trying to do, your question is an [xy problem](http://xyproblem.info/) and you should edit it to tell us what your actual goal is. –  Jul 16 '20 at 07:19
  • @ChrisG - i have an image url handy , from that i need to convert the same to file input . no matter i i convert to base64 or blob , anyway if there any possibility to get fileobject from image url – midhun k Jul 16 '20 at 07:23
  • You say the backend is expecting a File object. Can you confirm that this is about uploading via POST request? –  Jul 16 '20 at 07:30
  • yes we are using POST request @ChrisG – midhun k Jul 16 '20 at 07:32
  • 1. load the image 2. create a blob 3. append the blob to a FormData object 4. send the post request (see here: https://stackoverflow.com/a/39218720/5734311) –  Jul 16 '20 at 07:34
  • @ChrisG i tried but am. getting CORS Issue – midhun k Jul 16 '20 at 16:32
  • https://stackoverflow.com/questions/62938489/when-tried-to-convert-to-base64-from-url-getting-cors-issue-in-js issue am facing :( – midhun k Jul 16 '20 at 16:33
  • @ChrisG https://stackoverflow.com/questions/62938489/when-tried-to-convert-to-base64-from-url-getting-cors-issue-in-js am getting this when tried to do – midhun k Jul 16 '20 at 16:59
  • You can circumvent the CORS issue if you use an `` and set its `src`; loading the image using fetch will only work if shutterstock explicitly allows grabbing their images, not very likely. –  Jul 16 '20 at 20:25

0 Answers0