Comments (2)
I used your code as reference in order to pass the file using JSON, and I ran into the problem you had as well and figured out the issue. Take a look at my solution below:
uploadByFile(file) {
let reader = new FileReader();
reader.onload = function (e) {
return fetch('/uploadFile', {
method: 'post',
body: JSON.stringify({
file: e.target.result,
filename: 'first_img'
})
}).then(function(response) {
return {
success: 1,
file: {
url: 'https://my-photo-gallary.s3.ap-south-1.amazonaws.com/go_that_extra_mile.png'
}
}
})
};
// Read the file
reader.readAsDataURL(file);
}
You needed to use FileReader()
, and then load the image which is sent to the server in your JSON object, passing it as a base64 image.
You can then use fs.writeFile
or fs.writeFileSync
to save the image where you want.
Hope that helps :)
from image.
I had tried the way @tnylea mentioned, but didn't work due to my server (s3 compliance) response that put file as base64 in json is a "Bad Request", so i use another solution, just use FormData, and should be acceptable by most servers.
...
uploadByFile(file) {
let fd = new FormData();
fd.append('file',file);
return fetch('/uploadFile', {
method:'POST',
body:fd
}).then(res=>res.json())
.then(response => {
return {
success: 1,
file: {
url: 'https://your-url/'+response.your_file_uri
}
}
})
}
...
from image.
Related Issues (20)
- Cannot assign to read only property 'caption' HOT 3
- imageUploader HOT 4
- CDN example
- SVG Icon Disappears When Using buttonContent in ImageTool Configuration
- Canβt un streatch once stretched HOT 1
- Redirected images cannot be displayed
- Option to remove caption and extra features (border, stretch, etc.) HOT 2
- Option to add more options for image upload
- Add images without backend
- Dragging an existing image duplicates it
- Copying Images from Word or Google Doc
- Warning: `appendCallback` hook is deprecated
- Add link to image (make image a clickable link) HOT 1
- The onChange function is not being triggered when the caption of image is made blank.
- Pasting a picture from the clipboard after pasting a picture URL from the clipboard HOT 1
- How to pass temporary url
- Picture being pasted twice HOT 1
- {success: 0} not working!
- `additionalRequestHeaders` no longer working in v2.9.1 HOT 2
- upload api broken
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from image.