Hello everyone,
I have my form on “example1.com” domain and i have my endpoint set to “example2.com/upload”.
However my second server fails to read the file since it says that the Content-type isn’t multipart/form-data.If i set my endpoint to “/upload” and handle the files on the same server,it works however.
Is that normal behaviour?
I am running a Go server for both of those servers.
Here is a snippet of the .html
<script src="https://transloadit.edgly.net/releases/uppy/v1.3.0/uppy.min.js"></script>
<script>
var uppy = Uppy.Core()
.use(Uppy.Dashboard, {
inline: true,
target: '#drag-drop-area'
})
.use(Uppy.XHRUpload, {
endpoint: 'http://example2.com/upload',
fieldName:'uploadFile'
})
uppy.on('complete', (result) => {
console.log('Upload complete! We’ve uploaded these files:', result.successful)
})
</script>
and here is a snippet of the Go server
func uploadFileHandler(w http.ResponseWriter, r *http.Request) {
enableCors(&w)
file,_,err := r.FormFile("uploadFile")
defer file.Close()
fileBytes, err := ioutil.ReadAll(file)
newFile,_ := os.Create(newPath)
defer newFile.Close()
_,err := newFile.Write(fileBytes)
}
func enableCors(w *http.ResponseWriter) {
(*w).Header().Set("Access-Control-Allow-Origin", "*")
(*w).Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET")
}
and here’s a picture of the error