#[SOLVED] storage.createFile() not uploading, get undefined or network request failed

11 messages · Page 1 of 1 (latest)

drifting geode
#

Hi there, please if anybody can, help me to solve this ridiculous issue.

So, I pick an image file with this code (image 1) it works perfectly by giving back this object:

{"assetId": null, "base64": null, "duration": null, "exif": null, "fileName": "1000021004.jpg", "fileSize": 1733865, "height": 3200, "mimeType": "image/jpeg", "rotation": null, "type": "image", "uri": "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540anonymous%252Fdonify-cff8f0d0-4436-4e0c-a7f7-f1ce3e30de03/ImagePicker/1b176a9b-93fb-4645-9a2f-af1dc1932e64.jpeg", "width": 1440}

Then it gets passed on to the uploadFile functun, where it was supposed to be uploaded to my storage in Appwrite (image 2)

The storage.createFile() func doesn't seem to be working. I have stripped my whole code down just to try to upload an image hard-coded, I deleted the mimeType assets and tried just the filepath, I tried to hard-code the name, size, type and uri of the file as well. I always and every time get back the same 'undefined'.

I am also logged in within my app with a user, and gave all the necessary permissions for a file upload.

And then if I try to pick an image with the expo-document-picker, when it gets to uploading it, is gives me promise rejection, Error: AppwriteException: Network request failed.

magic haven
#

Or at least it's not set in the parts of the code that you sent

drifting geode
# magic haven I think asset is null since you have not set it?

It's definitely set. It gives back this object when I log it:

{"assetId": null, "base64": null, "duration": null, "exif": null, "fileName": "1000021004.jpg", "fileSize": 1733865, "height": 3200, "mimeType": "image/jpeg", "rotation": null, "type": "image", "uri": "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540anonymous%252Fdonify-cff8f0d0-4436-4e0c-a7f7-f1ce3e30de03/ImagePicker/1b176a9b-93fb-4645-9a2f-af1dc1932e64.jpeg", "width": 1440}

#

Coming from result.assets[0] and then that's the 'file' argument in the uploadFile(file)

#

Ahhhh, I've just found a similar topic on here and it solved it. I just had to distribute the assets object to this: {
name: asset.name,
type: asset.mimeType,
size: asset.size,
uri: asset.uri
}

gilded furnace
#

[SOLVED] storage.createFile() not uploading, get undefined or network request failed

true sapphire
languid vine
#

I just started using Apryse tonight. I am trying to create a user but I keep getting this error

[AppwriteException: Network request failed]

import { Client, Account, ID } from 'react-native-appwrite';

export const config = {
//all required ids here
};

// Init your React Native SDK
const client = new Client();

client
.setEndpoint(config.endpoint) // Your Appwrite Endpoint
.setProject(config.projectId) // Your project ID
.setPlatform(config.platform) // Your application ID or bundle ID.
;

const account = new Account(client);
export const createUser = () => {
// Register User
account.create(ID.unique(), '[email protected]', 'password', 'Jane Doe')
.then(function (response) {
console.log(response);
}, function (error) {
console.log(error);
});
}

magic haven
pine gazelle
#

Hello, Guys i am having the same issue with expo image picker, Below is my code, i pick image from expo image picker, compress it using expo image manipulator, convert it into blob and upload it to appwrite, In web and IOS it completely runs fine but in android only it gives problem, the error i get in console is Network request failed, when i use developer tools for android and i check network tab it shows, The Empty file passed to the endpoint.

The below is the function i use -

`const pickImage = async () => {
if (imageList.length >= 5) {
alert("You can only upload a maximum of 5 images.");
return;
}

let result = await ImagePicker.launchImageLibraryAsync({
  mediaTypes: ImagePicker.MediaType,
  allowsEditing: true,
  aspect: [4, 3],
  quality: 1,
});

if (!result.canceled) {
  setCompressing(true);
  const imageUri = result.assets[0].uri;

  try {
    // Compress and resize the image
    const compressedImage = await ImageManipulator.manipulateAsync(
      imageUri,
      [{ resize: { width: 500 } }], // Resize width to 500px
      {
        compress: 0.4,
        format: ImageManipulator.SaveFormat.JPEG,
      }
    );

    // Fetch the file as a blob
    const response = await fetch(compressedImage.uri);
    const blob = await response.blob();

    const res = await uploadImageApi(blob);

    // Get the public URL of the uploaded image
    const fileId = res.$id;
    const publicUrl = `https://cloud.appwrite.io/v1/storage/buckets/6749c792002950c03a16/files/${fileId}/view?project=6749c7010005f7cfffea`;

    if (publicUrl) {
      setImageList((prevImages) => [...prevImages, publicUrl]);
    }
    setCompressing(false);
  } catch (error) {
    setCompressing(false);
    console.error("Error uploading image:", error);
  }
}

};`