Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

image url to file js

const url = "https://cdn.shopify.com/s/files/1/0234/8017/2591/products/young-man-in-bright-fashion_925x_f7029e2b-80f0-4a40-a87b-834b9a283c39.jpg"
const fileName = url.substring(url.lastIndexOf('/')+1)

fetch(url)
   .then(response => response.blob())
   .then(blob => new File([blob], `${fileName}`, {
   		type: blob.type
	}))
   .then(file => {
   		setFileData(file);
   		setPreview(URL.createObjectURL(file));
	})
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #image #url #file #js
ADD COMMENT
Topic
Name
3+5 =