'How to fix enoent error for uploading photos on website?
I'm learning about react and express and I'm trying to run Tim's Instagram Clone project on my VS Code. I run it on my localhost and I'm stuck on one part of the code. The part where you post the posts and edit profile with uploaded photo, whenever I upload a photo, it gave me a Internal Error 500 and in the terminal in VS Code, it gave me this error: Error: ENOENT: no such file or directory, open 'C:\Users\RaiqP\Desktop\Instagram Clone\api\public\1653095353054-Image.PNG' When I go check Sanity, I do not see the posts obviously, however the users database does update by creating new users, which means the database is still working fine.How do I fix this error?
Solution 1:[1]
When I want to accomplish what I understand you to be trying to accomplish I use the event pattern.
In your child form you would want an event to be called after your delay:
public partial class ChildForm : Form
{
public event EventHandler OnWaitCompleted;
public ChildForm(int interval)
{
InitializeComponent();
WaitTime(interval);
}
public void WaitTime(int interval)
{
Task.Delay(interval).ContinueWith((MethodInvoker) =>
{
OnWaitCompleted?.Invoke(this, EventArgs.Empty);
});
}
}
Then in your parent form you would setup your event handling action before you display the child form:
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void btnSpawnChild_Click(object sender, EventArgs e)
{
ChildForm cf = new ChildForm(5000);
cf.OnWaitCompleted += (obj, args) =>
{
LoadNextChild();
};
cf.Show(this);
}
private void LoadNextChild()
{
}
}
I think this method is better as it avoids having child forms trying to control the content of their parent, which should be the responsibility of the parent.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Travis McFarland |
