DEV Community

File upload with React, Express and Google Cloud Storage with folder structure

Faith Morante on November 23, 2019

For the front end, we will use FilePond. It has a plugin for React for file uploads that supports previews, validations, drag and drop, etc. NOTE: ...
Collapse
 
vijajsoninoetic profile image
vijaj-soni-Noetic

const [imgCollection, setImgCollection] = useState('')
const [client, setClient] = useState('')
const [section, setSection] = useState('Section')

const onFileChange = (files) => {
    let items = files.map(fileItem => fileItem.file)
    setImgCollection([...imgCollection, items])
}

where i use these line of code its given me error

Collapse
 
idiglove profile image
Faith Morante

Hello,

What error do you get? Note, I'm using React Hooks.

Collapse
 
rterrell25 profile image
Robert Terrell

I noticed when i submit a file using the form it uploads correctly but for some reason it turns red and states error during load. My console shows the following: filepond.js:3139 GET localhost:3000/%5Bobject%20Object%5D 404 (Not Found) is there something I need to do to prevent this?

Collapse
 
idiglove profile image
Faith Morante

I wont be able to see that link as it is served through your localhost. Can you provide a screenshot of the error? thanks

Collapse
 
rterrell25 profile image
Robert Terrell • Edited

That's what the error displays as in the console. The error message is the following:

"filepond.js:3139 GET localhost:3000/%5Bobject%20Object%5D 404 (Not Found)"

the file input turns red and continually flickers saying error during load. What's strange tho is that the file uploads correctly and displays, so im wondering if its the file change code that's possibly creating the error.

Collapse
 
anuradha677 profile image
Anuradha677

Hi
I am using express-fileuploader for uploading the files. Cloud you please tell me how to use that to upload the image to storage?

Thanks in advance.

Collapse
 
idiglove profile image
Faith Morante

Please refer to their documentation. I haven't used that, sorry

Collapse
 
rterrell25 profile image
Robert Terrell

You've never once called your onSubmit function, where exactly are you using it

Collapse
 
idiglove profile image
Faith Morante

Sorry about that, the onSubmit was on my form tag. Will update my post now :)

Collapse
 
rterrell25 profile image
Robert Terrell

thanks

Collapse
 
sboudouk profile image
Sami

So you're basically uploading 2 times: On your servers, then on Google Cloud Platform ?

Collapse
 
idiglove profile image
Faith Morante

on GCP only

Collapse
 
dikshit1805 profile image
dikshit n

How do we handle upload files greater than 30MB ??