-
Notifications
You must be signed in to change notification settings - Fork 169
Closed
Description
I am making a react native application and I need to upload a file (specifically an Image) onto pocketbase through the app. However, pocketbase will upload the all the other information omitting the image. I have tried :
- Uploading the image asset returned by expo-image-picker directly into pocketbase through the js-sdk in a dictionary
- Uploading the image uri returned by expo-image-picker directly into pocketbase through the js-sdk in a dictionary
- Uploading the image asset returned by expo-image-picker into a FormData into pocketbase through the js-sdk
- Uploading the image uri returned by expo-image-picker into a FormData into pocketbase through the js-sdk
- Using the image uri to fetch a blob from the file system to place in a dictionary to then upload to pocketbase
- Using the image uri to fetch a blob from the file system to place in a FormData to then upload to pocketbase
- Using the image uri to fetch a blob from the file system to place in a Javascript file object to place into a Dictionary/FormData to then upload to pocketbase
- Using the image base64 to create a blob to place in a dictionary to then upload to pocketbase
- Using the image base64 to create a blob to place in a Formdata to then upload to pocketbase
- Using the image base64 to create a blob to place in a javascript file object to put in a dictionary to then upload to pocketbase
const base64String = base64Data.startsWith("data:") ? base64Data.split(',')[1] : base64Data;
const binaryString = decode(base64String);
const uint8Array = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
uint8Array[i] = binaryString.charCodeAt(i);
}
const blob = new Blob([uint8Array], { type: "image/jpeg" });
return blob;
}
async function ImageCreateData() {
const pb = new PocketBase(ngrok);
try {
let formData = new FormData()
const addy = await pb.collection('Addresses').getFirstListItem(`Address = '${address.Address}' && User = '["${userId}"]'`);
const imagefile = base64toFile(image.base64)
const imgdata = {
"Image": new File([imagefile], 'image'),
"Address": addy.id,
"Caption": caption,
"User": `["${userId}"]`
}
const imgrecord = await pb.collection('Images').create(imgdata);
navigation.goBack()
} catch (error) {
console.log("Error creating tenant:", error);
setError(true)
}
}```
This was my last attempt help will be appreciated greatly
Metadata
Metadata
Assignees
Labels
No labels