
I can't figure it out how to download image in .png by it's URL or Base64 string, I'm using Nodejs environment and get image in a two ways: Base64 string or URL. Seems like non of InputFile methods can do it without some additional action. Could anyone provide me a right direction, please?

Save image.png into Storage using Functions

π So you're trying to get an image from the internet and put it into Appwrite's storage service right?

Hmmmmm

Have you sanity checked your code outside an Appwrite function?

Nope, just wonder if it possible to make it work with Appwrite tools only

π Hmmm lemme play around with it, it should be possible.

You may need a system library from node to save image to buffer or smthing, lemme try it.

Node.js file handling hurts my eyes but:
import { Client, ID, Storage, InputFile } from 'node-appwrite';
import fetch from "node-fetch";
import fs from "fs";
const client = new Client()
.setEndpoint('https://localhost/v1') // Your API Endpoint
.setProject('test-self-signed') // Your project ID
.setKey('SECRET') // Your secret API key
.setSelfSigned()
;
// Init SDK
const storage = new Storage(client);
fetch("https://fastly.picsum.photos/id/641/200/300.jpg?hmac=TpiMIigzR3rlnmP84Df902LYzuV4pApn7Tq6lCYic0A").then(res => {
const promise = storage.createFile('default', ID.unique(), InputFile.fromStream(res.body, 'image.jpg'));
promise.then(function (response) {
console.log(response);
}, function (error) {
console.log(error);
});
}
);

This would work

I'm more familiar with the fetch interface from node.js, which returns the body as a stream

But I'm sure there's a million other ways to do this, it's just finding smthing that gives you what you need

That helps a lot. Thank you! But another issue: how can I show this image to the cleint (provide URL from my bucket)? I'm trying to use this one:
http://localhost/v1/storage/buckets/{BUCKET_ID}/files/{FILE_NAME}/view
but got 404. What I did wrong?

Make sure the user has access to the file. Check that the fallback header or Appwrite cookie is sent in the network request. If not, you may need to make sure your Appwrite endpoint and front end app are on the same base domain

Bucket accessible for Any role and coockie is setup

if it's set to any, then no cookie should be required.
maybe you're missing the project id: https://appwrite.io/docs/rest#no-headers

Got it, thanks Steven! You saved my day π

If the issue is fixed, remember to mark the thread title as resolved

[REOLVED] Save image.png into Storage using Functions

[SOLVED] Save image.png into Storage using Functions
Recommended threads
- Login/Logout Issue and Page Display Desp...
Subject: Login/Logout Issue and Page Display Despite System Downtime at app.animtube.xyz Hello Appwrite Support Team, After the domain change I made recently (...
- Using Appwrite along with Twilio - Deplo...
Stuck on Querying user document...
- Bypass Error When Creating Account With ...
Suppose user first uses email/pass for log in using xyz@gmail.com, few month later on decides to use google oauth2 with same xyz@gmail.com (or in reverse orde...
