how can i retrieve the path to a certain image file in a shared project?

If you want to upload the image with Stream , you could check the following code

private async Task<string> UploadImage(Stream FileStream)
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri("");
            MultipartFormDataContent form = new MultipartFormDataContent();
            HttpContent content = new StringContent("fileToUpload");
            form.Add(content, "fileToUpload");
            content = new StreamContent(FileStream);
            content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                Name = "fileToUpload",
                FileName = "xxx.png"
            var response = await client.PostAsync("", form);
            return response.Content.ReadAsStringAsync().Result;

Option 2:

You could also use the plugin FileUploaderPlugin . It support uploading multiple files at once

Uploading from a file path

CrossFileUploader.Current.UploadFileAsync("<URL HERE>", new FilePathItem("<REQUEST FIELD NAME HERE>","<FILE PATH HERE>"), new Dictionary<string, string>()
               {"<HEADER KEY HERE>" , "<HEADER VALUE HERE>"}

Option 3:

The first parameter of MultipartFormDataContent is HttpContent. To handle the stream, try using the StreamContent type which inherits from the HttpContent. Get the streamContent from the stream and add id to the MultipartFormDataContent.

string avatarFileName = "Avatars." + selectedAvatar;
var assembly = typeof(ProfilePage).GetTypeInfo().Assembly;
var stream = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.{avatarFileName}");
var streamContent = new StreamContent(stream);
content.Add(streamContent, "file", avatarFileName);

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top