Do ZeroQL support file sending?
I have not found an example or words about sending a file to GraphQL in the documentation. I had problems using GraphqlClient to send files. Can I use ZqroQL for it?
GraphQL has a special way to upload a file via the Upload type. This way is not supported.
The workaround would be to pack the file into the base64 string and send it like a simple string. Also, you can create a REST endpoint to do that.
Meanwhile, I think I can look at it, but I don't think it will be fast. It requires significant changes inside to make it work.
Thank you for so fast answer. Actually I've already solve this problem using standard HttpClient, MultipartFormDataContent and file mapping to contexts. It was required to simulate the structure of the http request to GraphQL with Upload file type.
I afraid to offer my help, though :D
Meanwhile, I think I can look at it, but I don't think it will be fast. It requires significant changes inside to make it work.
Hi ! I'm also interested in this feature !
@ShSSP : Can you share some code to show how you did it ? Thanks a lot.
In progress
@GautierT, it was something like that: `
var images = new[] { new { Name = "file.txt", Bytes = new byte[10] } };
var query = $"mutation ($images: [Upload]) {{..}} ";
var variables = new { images = Enumerable.Repeat<object>(null, images.Length) };
var index1 = 0;
var mapings = string.Join(",",
Enumerable.Range(0, images.Length)
.Select(x => @$"""{index1}"":[""variables.images.{index1++}""]")//"images" = $images
);
var map = $"{{{mapings}}}";
var form = new MultipartFormDataContent();
var operationsJs = JsonConvert.SerializeObject(new { query, variables });
form.Add(new StringContent(operationsJs), "operations");
form.Add(new StringContent(map), "map");
var index2 = 0;
foreach (var i in images)
form.Add(new ByteArrayContent(i.Bytes, 0, i.Bytes.Length), (index2++).ToString(), i.Name);
using var httpClient = new HttpClient();
var response = httpClient.PostAsync(_endPointUrl, form).Result;
`
Thanks a lot @ShSSP !
@GautierT @ShSSP You can try version 2.0.0-preview.2. It has support for Upload type. Don't forget to update the CLI and the NuGet package.
You can use it like that:
var variables = new { Id = 2, File = new Upload("image.png", new MemoryStream()) };
var user = await client.Mutation(variables, (i,m) => m.AddAvatar(i.Id, i.File));
@byme8 Much appreciated. I'll try it as fast as possible!