I would need some help I have my own Project going on and i would need some help with how to upload images/files to database using entity framework code first
I want to be able to have form with content like title/bodytext etc and file uploading. I'm pretty new to c# or even web developing. I have a model class with Byte[] but when I upload it to db it says null.
And then when I loop through database, I want to display the title, body text and the image I uploaded for each post I did.
Related
I am working on a ruby on rails project with a requirement of creating a Deal model with an image associated with it, it has other attributes as well but I want to focus on the image aspect. I was thinking about implementing the model by having an attribute called image_file_name. This string will contain the name of the image file. I will store the image file in the folder /app/assets/images. Is this the right way to go about things? I feel that this is the wrong place to place data related files within the application. Where would I keep such image or other media data within the project folder(If I am not using a 3rd party service like AWS).
I am working on a rails engine that uploads a excel file, validates it and if there is no error than it will save it to database.
Now when ever a user mounts the engine and than go to the route provided by engine. He will have a form to upload the excel file. There are two buttons on page, i.e, upload and validate.
Once a user choose the file and when he click on upload i want that file only gets uploaded and don't get saved in db. Once i get the message the file is uploaded successfully, than i will validate the file. If it is a valid excel file with valid data than it will be saved into db. Now i am not getting how to go about it. I have seen this Railscasts video on uploading csv and excel file but here he is performing validation and save operation with import action but i want validation and save operation when user clicks on validate action. This Questions seems similar to my problem but i am not getting how do i access that uploaded file. I don't want that file to be saved in database. I mean when a user click on upload button that file gets only uploaded not saved. Than i will validate that file and save it's content to db.
This may seem very easy and simple questions for some experts but i am very new to rails and i am not sure how to go about it.
Someone please help me with a sample code, so that i can understand the workflow. Also note that both upload and validate actions are on same page. So when a file gets uploaded it needs to be stored somewhere temporarily, this is the first problem i am facing. I can do all the task if someone can tell me workflow with a sample code about uploading excel file. I am only having problem here that as both upload and validate action are on same page, so after upload request it needs to be on that page so that i can validate that file.
Any help would be appreciated, I am very beginner at rails and really confused here.
Two options:
Write code to upload the file and save to DB with a validated column set to false. Then the 'validate' button will locate the unvalidated file, validate it and set validated to true. You could have a periodic job deleting unvalidated files of a certain age. If you do this, use a helper gem like Paperclip.
Forego file upload frameworks and just manually save uploaded files to Tempfile.new 'spreadsheet'. This guide takes you through how to do that. Save that filename to session and use it to validate at a later point. When you're finally ready to persist to DB, again, consider using a helper gem.
I tried to apply the method on this page, but this sample save the files to disk instead of Database. So, could you please inform me what changes should be made on the sample method or is there any sample using this Kendo Upload to save multiple files to database?
The following method declaration -
private IEnumerable<string> GetFileInfo(IEnumerable<HttpPostedFileBase> files)
which receives the uploaded files have IEnumerable<HttpPostedFileBase> as parameter. It is collection of all the uploaded files. Each file exposes a property InputStream. For more information visit this msdn page
So now that you have the file content in form of stream, convert this stream into byte[] and save this to database.
Some suggestion are posted here.
There is a lot of information in the title of the question !
I'm aware of Rails gems to upload files, parse Excel, etc. but I would like to know which solution will work nice in a Backbone app (that is, I don't want to reload the page during the upload). Is there a Backbone extension for that ?
The story is: the user wants to upload an Excel file, she browses her filesystem, selects the file, click "upload"... and then the Backbone app shows the content of the file (I don't need to store the file on the server).
Well, i dont think there is any backbone extension for that :) What you need is some upload extension like uploadify of http://blueimp.github.com/jQuery-File-Upload/ . You will bind the
success method to uploader and then you can do anything with the data returned from server.
I have an application where I allow my users to upload a file of any type. I save this in the file system on the server. The application will only be accessed by two users, so I don't need to worry about uploading any dodgy files.
How do I allow my user to press a button on an MVC form to request the file be sent back via the browser and be presented with the standard save/open dialog?
I want to return any type of file, and the example I've found always specify the type of file being returned. Is there a simple example of this?
See FileResult and derived classes.
An alternative approach is to set HttpContext.Response.ContentType to the proper mimetype and then writing the contents of the file with HttpContext.Response.OutputStream.Write ().
Useful if, for example, the data is not in a local file but stored in a database as a binary blob.