uploading to public directory
Unanswered
American Chinchilla posted this in #help-forum
American ChinchillaOP
Hello all, I am attempting to use the next api to handle a sharex upload. As such I need to be able to access
Clearly I am doing something wrong here and have been fighting with it for a while just wondering if anyone could point me in the right direction.
I am looking to upload the file to the websites public dir/folder. Uploading to the public dir obviously is temporary will be adding a database to handle the images once I get the upload portion working.
req.files.sharex using multipart form data to get the file/form data but when I attempt to do that using the basic NextJS api it says cannot read property sharex of undefined.Clearly I am doing something wrong here and have been fighting with it for a while just wondering if anyone could point me in the right direction.
I am looking to upload the file to the websites public dir/folder. Uploading to the public dir obviously is temporary will be adding a database to handle the images once I get the upload portion working.
37 Replies
@American Chinchilla Hello all, I am attempting to use the next api to handle a sharex upload. As such I need to be able to access `req.files.sharex` using multipart form data to get the file/form data but when I attempt to do that using the basic NextJS api it says cannot read property sharex of undefined.
Clearly I am doing something wrong here and have been fighting with it for a while just wondering if anyone could point me in the right direction.
I am looking to upload the file to the websites public dir/folder. Uploading to the public dir obviously is temporary will be adding a database to handle the images once I get the upload portion working.
regardless of what you try to do in the api route, you cannot upload to
publicpublic is read-onlyfor writes to the
public folder to be recognised by the server you need to restart the server (if you self host) or rebuild the app (if you use vercel)you need to upload to aws s3 or cloudflare r2 or similar services instead
@joulev for writes to the `public` folder to be recognised by the server you need to restart the server (if you self host) or rebuild the app (if you use vercel)
American ChinchillaOP
Ahh okay see I was confused cause rn I’m using formidable to handle the file data and pass it around then fs to write file and running it locally works like a charm but once I host the site in prod the req times out
When I use the default NextJS api routes with no middleware is when I get the issue stated in the original message
When I use the default NextJS api routes with no middleware is when I get the issue stated in the original message
So seems like my best option might just be a DB
You may find the next-upload package useful
@linesofcode You may find the next-upload package useful
American ChinchillaOP
I was looking into this package but actually got it working using formidable and uploading to a folder that’s not the public dir. allowed my Linux user to have ownership of that folder and works like a charm
Ah okay
That definitely works if you’re deploying to a vps
@linesofcode That definitely works if you’re deploying to a vps
American ChinchillaOP
If i wanted to deploy to vercel what you suggested would be an option?
But not serverless / vercel
Yeah it would be
There is only a tmp file system in vercel
So you need some form of object store and api to interact with it
American ChinchillaOP
Ahh that makes sense actually see I was stuck wondering why vercel struggled to let me upload but the code I had worked fine locally
Locally meaning localhost
@linesofcode So you need some form of object store and api to interact with it
American ChinchillaOP
I honestly might look into your option I would love to host it on vercel but the image uploading side of the site doesn’t like the way I currently have it setup.
Will have to look into fixing it!
Will have to look into fixing it!
There’s an example app in that packages repo
Which shows end to end image uploading
If it helps
I’ve deployed it to vercel to confirm it works
American ChinchillaOP
If it makes it an easier what I’m trying to do I’m basically trying to make a website that handles sharex screenshot uploads.
All you need is an s3 or similar api key
@linesofcode I’ve deployed it to vercel to confirm it works
American ChinchillaOP
Awesome I’ll take a look at it later today thanks! And I actually have one of those.
American ChinchillaOP
Would this work with digital ocean spaces?
Still a bucket
It should yeah
It uses minio js under the hood for a universal s3 client
If digital ocean is compliant with s3 then it’s just a matter of finding the api keys and endpoint
The example runs out of the box with minio locally so you can test it
@linesofcode If digital ocean is compliant with s3 then it’s just a matter of finding the api keys and endpoint
American ChinchillaOP
It should be Ive tested out how I can interact with it and so far even the s3 sdk works with it as long as you know how to use the sdk
American ChinchillaOP
Thanks will let you know if I have any questions