#How to Saving Images to Public Folder?

1 messages · Page 1 of 1 (latest)

full field
#

I want to save some images to my server so I tried using postman to post Image
However When I POST the image but nothing saved on my Public Folder
How can I solve this??
I also setup middleware by adding this code
app.middleware.use(FileMiddleware(publicDirectory: app.directory.workingDirectory))

shrewd pelican
#

@full field 2 things; first of all, please look up proper sanitisation. Because you're not catching ".." (parent) directories

#

And second, you should consider printing the uploadPath after combining it with the filename. It's possible you're missing the trailing / for the publicDirectory.

#

Also , I'd recommend building an API that does throw the error up, rather than hiding it in a string. Vapor's ErrorMiddelware can do the right thing here, or you could even customise the ErrorMiddleware for your specific error handling behaviour globally

#

Finally, I did see you're mapping the files over to a writeFile. WriteFile will return a future, which you seem to be ignoring. So the route can finish with the file not being processed yet. If you'd immediately render this image after upload, such as a profile image, that can be pretty odd to debug

#

I assume you've already looked into this (otherwise your route wouldn't be 200 OK), but Vapor has a maximum body size for requests. If you didn't update the maximum body size, most images wouldn't be small enough to fit in - and the request would be rejected

full field
#

oh.. Thanks for help! The problem was
"req.application.directory.publicDirectory" was not a spot I want to save