I'm currently using an external piece of software that I'm trying to plug into my own SaaS. The software has an image upload function and has allowed me to connect it to our Amazon S3 storage and automatically uploads the file there.
However, we want to be able to handle it first and THEN upload afterwards.
The software documentation details this particular function for handling image uploads yourself
editor.registerCallback('image', function(file, done) {
var data = new FormData()
data.append('file', file.accepted[0])
fetch('/Webservices/MyService.asmx/UploadImage', {
method: 'POST',
headers: {
'Accept': 'application/json'
},
body: data
}).then(response => {
// Make sure the response was valid
if (response.status >= 200 && response.status < 300) {
return response
} else {
var error = new Error(response.statusText)
error.response = response
throw error
}
}).then(response => {
return response.json()
}).then(data => {
// Pass the URL back mark this upload as completed
callback({ progress: 100, url: data.filelink })
})
})
When I log data.get('file') to the console, before the fetch, it comes out as:
File(36071)
{
lastModified :1510142017134
lastModifiedDate: Wed Nov 08 2017 11:53:37 GMT+0000 (GMT Standard Time) {}
name: "477.gif"
size :36071
type: "image/gif"
webkitRelativePath:""
}
This is the following on the server side:
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public string UploadImage(byte[] file)
{
return "hello";
}
I don't know what parameter the file should be on the server side (to replace byte[] file) to be able to get any further with it.