Base solution for your next web application
Open Closed

Upload image via multipart formdata in angularjs SPA #680


User avatar
0
otgontugsmiimaa created

Hi there, I'd like to organize an entity which have name and image attributes like:

public class User 
{ 
public string Name{get;set;}; 
public "sometype_for_storing_image" ProfileImage{get;set;}; 
}

I've a input form <input type=text name=Name/> <input type=file name=ProfileImage/>. Then i need to save the form data to the database.

Can "sometype_for_storing_image" be BinaryObject class? If yes what would the DTO, form and JS look like?

I've seen GetProfilePicture, ChangeProfilePicture actions in ProfileController example. But it uses angular fileUploader module. This is non-transactional and i don't want to store bunch of useless images if form data is invalid.

Thanks


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    sometype_for_storing_image can be BinaryObject. As an alternative, you can just hold a reference to a BinayObject (just like I did for User's profime image). Then access to binaries only via BinaryObjectManager. Thus, you can change your binary storage later (you may want to store in a different DB or even in file system) without changing your entities and other code.

    I've such an example. But this is not directly related to AspNet Zero. I'm sure that you can find examples or documents on the web since you can create regular forms and controllers within AspNet Zero.