so this is my code for posting
public async Task AddProduct(int productid, string productCategory, string productColor, decimal unitPrice, string userId,byte[]image)
{
var client = new HttpClient(); var model = new Products { ProductId = productid, ProductCategory = productCategory, ProductColor = productColor, UnitPrice = unitPrice, UserId = userId, // Image = image <<<< DO I ADD THIS? }; var json = JsonConvert.SerializeObject(model); var content = new StringContent(json); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await client.PostAsync("http://192.168.1.6:44331/api/Products", content); return response.IsSuccessStatusCode; }
My question is this. and I'm really so confused about this part. in my view there will be add product. thats looks something like this
StackLayout>
<Entry Text="{Binding ProductColor}" Placeholder="Enter Product Color"/> <Entry Text="{Binding ProductCategory}" Placeholder="Enter Product Category"/> <Entry Text="{Binding UnitPrice}" Placeholder="Enter Product Cost" Keyboard="Numeric"/> <Button Command="{Bingind AddProductCommand}" Text="Add Product"/> </StackLayout>
in my view model i am just calling that service to a command to add the product. So my question is how can i slid the image there and post it in one go.
Or at least upload the image to azure blob storage and return it as uri then post it with a single command. Give me an idea on how to do that please. I've been reading so much topic about this. and all they teach is how to upload the image without the data along with it