Upload files/images in baserow

Hi! I’m new to appgyver and I need a super help from you guys. I’ve been trying for three days to do a simple task that is uploading an image to baserow. The app should take an image from my gallery and upload it to baserow. However, I am not able to do this.

I’m uploading to the following api:
https://api.baserow.io/api/user-files/upload-file/

and then trying to send the result to a table of my baserow. I believe that the key to succeed in this operation is in the multipart file and that I don’t know how to create it. Could someone please help me?

If anyone has any other ideas on how to do this, I would greatly appreciate it!

capture 01







1 Like

I researched and used the javascript module, as per Uploading file to Directus (multipart/form-data). Unfortunately, on mobile it still didn’t work. I believe the secret is in the definition of the blob.

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,
      },
    },
  ]
}