Back

[SOLVED] .net sdk (beta) - createfile

  • 0
  • Storage
oferardi
24 Jun, 2023, 17:31

my problem is related to permitition - i get exception "e.Message = "Invalid permissions: Invalid permission string format: write.".. i tryed serval options like "any", "write", "files.write" in all of the i get exception.

TL;DR
The user had a problem with the .NET SDK for creating a file with Appwrite. They were using the `InputFile.FromPath()` method but it wasn't working. They asked for help from the SDK developer because the .NET SDK only had properties for `.path` and `.file`, and if `.file` is null, it raises an exception. They tried formatting the code using backticks and mentioned that the latest version they were using was 0.41. Someone suggested using the static method `InputFile.FromPath("[DIRECTORY_PATH]/nature.png")` and asked for the version of Appwrite being used. The user provided
Drake
24 Jun, 2023, 18:09

What is your code?

The examples wouldn't show permissions anyways.

And the permissions should be the same creating a document

oferardi
26 Jun, 2023, 20:31

using Appwrite; using Appwrite.Services; using Appwrite.Models; using System; using System.IO; using System.Net.Http; using System.Threading.Tasks; using System.Collections.Generic;

namespace playground_for_dotnet { class Program { static async Task Main(string[] args) { Client client = new Client();

TypeScript
        client.SetEndpoint("https://cloud.appwrite.io/v1");
        client.SetProject("");
        client.SetKey("");
        client.SetSelfSigned(true);

        //Storage
        Storage storage = new Storage(client);

        //BucketID
        string bucketid = "645b1e668687ffe89f12";

        //InputFile
        InputFile inputfile = new InputFile();
        inputfile.Path = @"c:\test\";
        inputfile.Filename = "nature.jpg";

        //Permitions
        List<string> perms = new List<string>() { Permission.Write(Role.Any()) };

        Action<UploadProgress> onProgress = null;

        try
        {
            Appwrite.Models.File uploadfile = await storage.CreateFile(bucketid, ID.Unique(), inputfile, perms, onProgress);
        }
        catch (AppwriteException e)
        {
            Console.WriteLine(e.Message);
        }

    }
}

}

oferardi
26 Jun, 2023, 20:34

Hi Steven, i resolved the permitions issue but i get exception 'System.InvalidCastException: 'Unable to cast object of type 'System.DateTime' to type 'System.String'.'"

oferardi
26 Jun, 2023, 20:34

i can not find what is the reason for that..

Drake
26 Jun, 2023, 20:51

Btw, it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting

Drake
26 Jun, 2023, 20:52

Do you have a full stack trace?

oferardi
27 Jun, 2023, 14:30

Hi i didnt manage to capture the fulk stack exception yet. i'm using the appwrite cloud. does the sdk beta if compatiable with the cloud version ?

Drake
27 Jun, 2023, 15:26

Maybe you can manually print the stack trace? How do you do that in dotnet?

Drake
28 Jun, 2023, 17:47

Actually, the fix for this should be coming soon

oferardi
28 Jun, 2023, 19:02

Thanks for the update. Does this bug is in the .net sdk or the rest api?

Drake
28 Jun, 2023, 19:11

SDK

oferardi
28 Jun, 2023, 19:12

Thanks

oferardi
7 Jul, 2023, 16:30

Hi, the crash is resolved with the new SDK version but when the file is upload it shown as size 0 and mime type: application/x-empty.

oferardi
7 Jul, 2023, 16:31

//InputFile InputFile inputfile = new InputFile(); inputfile.Path = @"c:\test; inputfile.Filename = "nature.jpg"; inputfile.MimeType = "image/jpeg";

TypeScript
        //Permitions
        List<string> perms = new List<string>() { Permission.Write(Role.Any()) };

        Action<UploadProgress> onProgress = null;

        try
        {
            Appwrite.Models.File uploadfile = await storage.CreateFile(bucketid,ID.Unique(), inputfile, perms, onProgress);
        }
        catch (AppwriteException e)
        {
            Console.WriteLine(e.Message);
            //Console.WriteLine(e.StackTrace);

        }
Drake
7 Jul, 2023, 16:31

what version of Appwrite?

Drake
7 Jul, 2023, 16:32

don't forget to format code using backticks

Drake
7 Jul, 2023, 16:35

also, we typically use the static methods for instantiating InputFile like InputFile.FromPath("[DIRECTORY_PATH]/nature.png")

oferardi
7 Jul, 2023, 16:37

latest - 0.41

oferardi
7 Jul, 2023, 16:42

with the .net SDK there is no ".Fromfile is has only properties of .path and .file. if the .file is null than exception is raised. the website docs doesn't have examples for c# yet so i'm trying that it will work

oferardi
7 Jul, 2023, 16:44

it not working event like that with the .path property. can you ask from the .net sdk developer to look on that ?

oferardi
7 Jul, 2023, 16:52

resolved...thanks. ( Appwrite.Models.File uploadfile = await storage.CreateFile(bucketid,ID.Unique(), InputFile.FromPath("c:/test/nature.jpg"), perms, onProgress);

Drake
7 Jul, 2023, 16:54

Appwrite, not the SDK

oferardi
7 Jul, 2023, 16:55

I<:github:1112062009194848336> t's working so thank you steven..

Drake
7 Jul, 2023, 17:00

[SOLVED] .net sdk (beta) - createfile

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