Gitanes
06/14/2022, 7:04 PMevent.target[2].files[0]
to the api but I wonder if i'm not losing data js
// frontend code
saveTestimonial(evt) {
this.isFetching = true
const data = new FormData()
data.append('description', this.description)
data.append('identity', this.identity)
data.append('picture', evt.target[2].files[0])
console.log(evt.target[2].files[0])
fetch('/api/testimonials-add', {
method: 'POST',
body: data,
})
// --- API code
const imageFile = data.files.picture[0]
const imagePath = `public/${imageFile.originalFilename}`
supabase.storage
.from('test_images')
.upload(imagePath, imageFile)
.then(async (response) => {
await this.supabase.from('testimonials').insert({
description: data.fields.description[0],
name: data.fields.identity[0].split('/')[0].trim(),
occupation: data.fields.identity[0].split('/')[1].trim(),
picture:
'https://qroiybphgipjhkmfsvnj.supabase.co/storage/v1/object/public/' +
response.data.Key,
})
})
Needle
06/14/2022, 7:04 PMGitanes
06/14/2022, 7:05 PMjson
data: {
"fields": {
"description": [
"It is a long established etc..."
],
"identity": [
"Ella Fitzgerald / Singer"
]
},
"files": {
"picture": [
{
"fieldName": "picture",
"originalFilename": "humble.jpeg",
"path": "/var/folders/h3/q50t1r917ddbn9xgzzr8z13w0000gq/T/5vrhgasyAb_V-kCHVFhJvZu4.jpeg",
"headers": {
"content-disposition": "form-data; name=\"picture\"; filename=\"humble.jpeg\"",
"content-type": "image/jpeg"
},
"size": 498889
}
]
}
}
garyaustin
06/14/2022, 8:21 PMGitanes
06/14/2022, 10:07 PMevent.target[2].files[0]
to the supabase object. now I do too but there is an extra step where i transform the data to form data. (yes i'm using service keys)garyaustin
06/14/2022, 10:13 PMGitanes
06/14/2022, 10:19 PMGitanes
06/14/2022, 10:19 PMGitanes
06/14/2022, 10:24 PMgaryaustin
06/14/2022, 10:24 PMgaryaustin
06/14/2022, 10:34 PMGitanes
06/14/2022, 10:35 PMGitanes
06/14/2022, 10:40 PMGitanes
06/14/2022, 10:46 PMjs
catch (error) {
await supabase.from('testimonials').insert({
description: error.message,
name: 'error',
occupation: 'error',
})
console.log(error)
response.status(500).json({ message: error })
}
garyaustin
06/14/2022, 10:48 PMGitanes
06/14/2022, 10:54 PMGitanes
06/14/2022, 10:55 PMgaryaustin
06/14/2022, 10:57 PMGitanes
06/14/2022, 11:00 PMGitanes
06/14/2022, 11:00 PM"/var/folders/h3/q50t1r917ddbn9xgzzr8z13w0000gq/T/5vrhgasyAb_V-kCHVFhJvZu4.jpeg"
garyaustin
06/14/2022, 11:12 PMGitanes
06/14/2022, 11:13 PMgaryaustin
06/14/2022, 11:15 PMGitanes
06/15/2022, 1:48 AMGitanes
06/15/2022, 7:58 AMjs
const imageFile = data.files.picture[0]
const imagePath = `public/${imageFile.originalFilename}`
fetch(imageFile.path)
.then(function (response) {
return response.blob()
})
.then(function (blob) {
supabase.storage
.from('test_images')
.upload(imagePath, blob)
Gitanes
06/15/2022, 7:58 AMUnhandled rejection: TypeError [ERR_INVALID_URL]: Invalid URL: /var/folders/h3/q50t1r917ddbn9xgzzr8z13w0000gq/T/Rep86P8lmnoMO9PHLnFvhOnB.jpeg
Gitanes
06/15/2022, 8:05 AMnwsursock@Nicolass-MacBook-Pro crdacode % ll /var/folders/h3/q50t1r917ddbn9xgzzr8z13w0000gq/T/Rep86P8lmnoMO9PHLnFvhOnB.jpeg
-rw-r--r--@ 1 nwsursock staff 498889 Jun 15 09:56 /var/folders/h3/q50t1r917ddbn9xgzzr8z13w0000gq/T/Rep86P8lmnoMO9PHLnFvhOnB.jpeg