Hello everybody!
I encountered such a problem.
I need to send a file with a request.
I read this post and helped to send the file to me:
[Typescript Servicestack-client post file and request][1]
[1]: Typescript Servicestack-client post file and request
But now the problem is that I can not send json objects, they are not deserialized on the server side and therefore the value is exactly null.
public class DTO {
public string uid { get; set; }
public string name { get; set; }
public CatalogItemStock stock { get; set; }
}
So I send the file and settings, except the stock all comes to the server.
var stock: CatalogItemStock = new CatalogItemStock();
stock.Stock = 10;
let dest1: StockDestination = new StockDestination();
dest1.Stock = 10;
dest1.Destination = 'London';
stock.StockDestination = [dest1];
var file = new File([''], 'file.txt');
var postUrl = 'http://url';
const formData = new FormData();
formData.append('uid', '123');
formData.append('name', 'name of item');
formData.append('file', file);
formData.append('stock', JSON.stringify(stock));
fetch(postUrl,
{
method: 'POST',
headers: {
Accept: 'application/json',
},
body: formData,
}).then(r =>{
console.log(r);
});
I very much ask you, tell me how it can be solved because I’m not a frontend programmer and have been racking my brains for several days
Thanks in advance!