to upload files server used ng-file-upload.in there send files form multi part.also can upload multiple files server.so far working text,xml , csv files.i not sure if did mistake enable other format jpeg,png , .xlsx file format.
here front end code snippet.
<div class="input input-file "><span class="button"><input name="files[]" ngf-select multiple accept="text/csv/xlsx/xls" ngf-pattern=".txt,.xml,.xls,.csv,.xlsx" ngf-max-height="1000" ngf-max-size="10mb" type="file" id="tattachments"name="file" ng-model="model_col_field" onchange="this.parentnode.nextsibling.value = this.value">browse</span> <input ng-class="\'colt\' + col.uid" ui-grid-edit-file-chooser id="attachments" type="text" placeholder="select files (optional)" readonly=""> </div>
i enabled following ng-file upload directives accept="text/csv/xlsx/xls" ngf-pattern=".txt,.xml,.xls,.csv,.xlsx"
request header details
content-disposition: form-data; name="files[0]"; filename="samplefile.xlsx" content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
i not sure if did mistake here.
back end code snippet save files db
private filesattachment addfileattachment(string filename, string filecontent, string mimetype) { filesattachment attachment = new filesattachment(); byte[] stream = filecontent.getbytes(); attachment.setdata(stream); attachment.settimestamp(calendar.getinstance().gettime()); attachment.setsize(stream.length); attachment.setfilename(filename); attachment.setdescription(filename); attachment.setmimetype(mimetype); return attachment; }
js code snippet
var promise= upload.upload({ url: rest end point url, data: { files: attachments, //file list contains selected files 'message':message, 'username': username }}).then(function (response) { etc ... }
then tried access files have uploaded cant open them.please let me know did wrong.
Comments
Post a Comment