
I tried this: (python)
file = "some data of file passed by frontend/client"
filepath = InputFile.from_bytes(file)
print(filepath)
response = storage.create_file('attachments', id_class.unique(), filepath)
and it gives the appwrite.exception.AppwriteException: Empty file passed to the endpoint.
error. I double checked the file var does contain the contents of the upload file from the frontend

the bucket has all perms for "Any" role

wait, if the file is not binary, does appwrite storage not see it as a file?

InputFile.from_bytes
needs your input to be a byte array
In case your input is of a different type, you'll have to convert it first

ohh, any idea on how to do that?

also, does the bucket accept all file types by default?

This depends on the data type you want to convert
For strings, this might help: https://blog.enterprisedna.co/python-string-to-bytes-3-easy-methods/

Yes

ok, thanks, I'll try this and get back to u

so I encode the file data to UTF-8? will appwrite accept it?

file = str(file).encode("utf-8")
print(f"FILE: {bytearray(file)}")
filepath = InputFile.from_bytes(bytearray(file))
print(f"FILEPATH: {filepath}")
response = storage.create_file('attachments', id_class.unique(), filepath)
is this correct?

The initial encoding depends on what datatype file
was present in, in the first place
For example, if it was a string
text_data = "Text data";
file = bytearray(text_data, "utf-8");
filepath = InputFile.from_bytes(file);
response = storage.create_file("attachments", id_class.unique(), filepath)
That being said, if instead of text_data, there's a variable representing a different type, you'll have to handle it accordingly

well, the data is going to be in string format. so I will try this method

I printed file
and it shows this type of bytearray, still appwrite classifies it at "empty":
(message.txt)

I'll try testing on my end too once, if that's the case

Ok, Thanks

π Oh yeah this is very common. Python has to many different types of bin, byte, byte array, hex, all kinds of stuff

I don't remember the exact encoding you need for it to work properly when sent over HTTP

Lemme check past projects to see if we have anything that would help

Oof, I've dealt with byteencoding before and it was always a pain

@Ryan You know what it is?

InputFile.from_bytes(file) is missing filename

π€£

The error message is confusing but it's because filename is optional in our SDK, but it shouldn't be π¬

Recommended threads
- File tokens regenerate each page reload
Hello, on appwrite 1.7.4, when I create a file token via the API Tokens(appwriteAdminClient)#createFileToken I get a secret, then when I check in the console t...
- CSV Import Shows Success but Data Not Ap...
I tried importing a CSV file into my PRODUCTS collection. The dashboard shows the message βImport to PRODUCTS completed successfully,β but no data appears in th...
- Console create row ui not passing ID.uni...
I'm getting an error saying the id is already used but it should be created with ID.unique() it doesn't seem to be reading the row ID field at all. I can't get ...
