The script works in the online preview https://platform.preview.appgyver.com/, but on mobile, this script doesn’t work. Could someone help me please, I urgently need this to work. This is the script that worked in the preview appgyver on the computer:
let { url, authorization, file } = inputs
const formData = new FormData()
// transform blob url into a blob
// "blob:https://platform.preview.appgyver.com/cc59fe7a-0fa3-4c4c-9343-656c2be2e6a1"
let blobResp = await fetch(file.path)
let blob = await blobResp.blob()
formData.append('file', blob, file.name)
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': authorization,
},
body: formData,
})
if (!response.ok) {
throw new Error('Unable to upload file to endpoint.')
}
const parsed = await response.json()
console.log('response:', parsed)
return [
0,
{
url: parsed.url,
name: parsed.name,
is_image: parsed.is_image,
image_width: parsed.image_width,
image_height: parsed.image_height,
uploaded_at: parsed.uploaded_at,
thumbnails: parsed.thumbnails,
size: parsed.size,
mime_type: parsed.mime_type,
},
]
} catch (error) {
console.error(error)
return [
1,
{
error: {
code: 'unknown',
message: 'Unknown error occurred while trying to upload file.',
rawError: error,
},
},
]
}
I saw another page that posted the script for beckendless and I tried to adapt. Unfortunately, this one didn’t work either for the preview on the computer or on the mobile.
let { url, authorization, file } = inputs
const formData = new FormData()
const imagem = {
uri: file.path,
name: file.name,
size: file.size,
type: 'image/jpg',
};
formData.append('image', imagem);
formData.append('update', "");
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': authorization,
},
body: formData,
})
if (!response.ok) {
throw new Error('Unable to upload file to endpoint.')
}
const parsed = await response.json()
console.log('response:', parsed)
return [
0,
{
url: parsed.url,
name: parsed.name,
is_image: parsed.is_image,
image_width: parsed.image_width,
image_height: parsed.image_height,
uploaded_at: parsed.uploaded_at,
thumbnails: parsed.thumbnails,
size: parsed.size,
mime_type: parsed.mime_type,
},
]
} catch (error) {
console.error(error)
return [
1,
{
error: {
code: 'unknown',
message: 'Unknown error occurred while trying to upload file.',
rawError: error,
},
},
]
}