Skip to content

📶Refit guidelines

Strypper Vandel Jason edited this page Feb 26, 2023 · 1 revision

Uploading files and images

  1. Create a StreamPart type first: _file is FilePicker service this is already built inside the project

StreamPart:

`_file = await filePicker.OpenMediaPickerAsync();`

`using var imageStream = File.OpenRead(_file.FullPath);`

`var imageFromStream = new StreamPart(imageStream, _file.FileName);`

ByteArrayPart:

`_file = await filePicker.OpenMediaPickerAsync();`

`var imageByteArray = await File.ReadAllBytesAsync(_file.FullPath);`

`var imageFromByteArray = new ByteArrayPart(imageByteArray, _file.FileName);`
  1. Put AliasAs to help Refit define the request body name better
     [Multipart]
     [Put("/User/UploadAvatar")]
     Task UploadAvatar([Authorize("Bearer")] string token, [AliasAs("avatar")] StreamPart avatar);