Reputation: 6083
I want to upload image from my Angular application to .net core api, because I want to save it in SQL database. To do this I adding image via:
<input type="file" accept="image/png, image/jpeg">
And I have object type of File
I found this tutorial for API which says that my property in backend should looks:
public byte[] ImageData { get; set; }
But I'm not quite sure how am I suppose to convert it to that type before I'll send it to API. Any idea?
Upvotes: 0
Views: 4392
Reputation: 266
I have one advice for you before you implement your solution
Storing files in Database is not best practice. Your database can become huge and serving those files could become costly to your code.
Instead, you can store those files as static to serve more efficiently. It’s a simple process, just save the metadata (size, file, type, etc) of those files, and store the path to serve after.
For more information, read here.
Or follow these steps:
Upvotes: 1
Reputation: 213
You can use a storage to upload your files/images, it should provide a URL for this media file, and you can store this URL in the SQL database. Please follow this link for better understanding assuming you will use firebase storage, but you can use any storage provider or build your own.
Upvotes: 0