Reputation: 954
In my React Native app, I want to use fetch to upload an image file to my server. I'm getting a 200 response, but the image does not upload. My fetch looks like...
let url = Config.base_url + '/photos'
let filename = this.state.image.substr(this.state.image.lastIndexOf('/') + 1)
// filename: something.jpg
let data = new FormData()
data.append('photo', {
uri: this.state.image,
type: 'image/jpeg',
name: filename
})
fetch(url, {
method: 'POST',
body: data,
headers: {
Accept: 'application/json'
}
}).then(res => {
console.log(res)
})
In the Apache error log there is no error.
The entry in my access log looks like...
123.45.67.89 - - [26/Jul/2018:18:47:30 +0000] "GET /photos/ HTTP/1.1" 200 649 "-" "Ally/1 CFNetwork/901.1 Darwin/17.7.0"
Upvotes: 1
Views: 600
Reputation: 153
It's kinda hard to tell without seeing your server code, but there are a few things you should check.
Your access log says "GET" although your code says it's using "POST". Are you sure that's the correct log entry?
In your server, in the function that receives the photo, can you log the incoming request? Try logging the body and seeing if it's what you expect to see.
Can you manually send a request from another service such as cURL or an app like this? If that works, then the problem is in how you are sending the request. If that doesn't work, it could be that there is an issue in your server.
Upvotes: 1