Back

Is my Syntax for file creation right?

  • 0
  • React Native
  • Cloud
SorryLad2
26 Nov, 2024, 00:06

I've been stuck on this for way too long.

I should be downloading the file as a stream and writing to a storage bucked with that stream, but I keep getting an error. Am I creating the file correctly?

TypeScript
// Download the image directly as a stream
    const imageResponse = await axios.get(output, { responseType: "arraybuffer", timeout: 10000}); // Use arraybuffer for compatibility

    // Convert the array buffer to a Buffer
    const imageBuffer = Buffer.from(imageResponse.data);

    // Upload the image to Appwrite storage directly
    const createFile = await storage.createFile(
      config.bucketId, // Replace with your Appwrite storage bucket ID
      ID.unique(), // Generate a unique file ID
      imageBuffer, // Pass the stream directly
      ["user:" + account_id] // Set user-specific permissions (read/write access)
    );
TL;DR
The developer is attempting to download an image file as a stream and write it to a storage bucket using Axios and Appwrite. They are converting the array buffer to a Buffer and uploading it to the storage directly. The issue may be related to how the file is being created in the bucket.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more