-
-
Notifications
You must be signed in to change notification settings - Fork 703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The image file url is not updating on the database [Chapter 4: Uploading File Api] #176
Comments
In the browser It upload the new image file but when I refresh it than it load old image files |
@rohidas-gowda Thanks for reporting. I was able to reproduce your issue in
Let me know if this solves the problem for you. I will add an extra note in that file to remind readers to add their own value. Note that we hard code this value only in Chapter 4. In Chapter 5, we show you how to get |
I had given the _id from my mongoDB database. If Id is not proper I am not able to upload the data to database. The Issue is when I modify the code url got updated to database. `this.setState({ await updateProfileApiMethod({ In the above code I will modify method updateProfileApiMethod 's avatarUrl from avatarUrl: this.state.newAvatarUrl to avatarUrl: responseFromApiServerForUpload.url. Than It's working fine, the url in the database also get updated. I think the problem is in setting the state and sending the same state url as avatarUrl. |
@rohidas-gowda thanks for following up. I am running Are you seeing this problem when you run our exact When you upload a new image, check the database. Do you see that |
@rohidas-gowda After you upload file, print value like this:
It should print new value because of:
If it does not print new value, you are welcome to share code with us (public repo). Thanks. |
The console.log(this.state.newAvatarUrl); prints the new value but inside updateProfileApiMethod method the avatarUrl is a old value. Here is my repo link (4-end): https://github.com/rohidas-gowda/saas/blob/master/book/4-end/app/pages/your-settings.tsx |
@rohidas-gowda Thanks for sharing your codebase. I compared your For instance, compare your To our You are missing some packages that we use, and you have packages that we don't use. You also have different versions of packages that we use. When I ran your Please try using the |
Thanks @klyburke this solved my issue. And also I hope you will update the packages to latest version. Thanks |
In "https://github.com/async-labs/saas/blob/master/book/4-end/app/pages/your-settings.tsx", the following code
`this.setState({
newAvatarUrl: responseFromApiServerForUpload.url,
});
await updateProfileApiMethod({
name: this.state.newName,
avatarUrl: this.state.newAvatarUrl,
});`
In the above code segment this.setState set newAvatarUrl from responseFromApiServerForUpload.url But In the method updateProfileApiMethod avatarUrl is set to old url, may be because of setState() delay.
But when I modified the code as following it worked fine:
`this.setState({
newAvatarUrl: responseFromApiServerForUpload.url,
});
await updateProfileApiMethod({
name: this.state.newName,
avatarUrl: responseFromApiServerForUpload.url,
});`
In the above code I directly pass the url from the responseFromApiServerForUpload.url to avatarUrl
So can I setState() and use that state newAvatarurl to the updatePropfileApiMethod 's avatarUrl?
The text was updated successfully, but these errors were encountered: