3
Answers

400 bad request angularjs and webapi

 iam getting bad request when i added iamge here 
 
https://test-a.gfxsymphony.com/v1/SurveyApp/AddImageToSection/387e6b32-c1ed-4177-9909-78b8b7e2b62d/Store%20and%20Contacts
 
 
fileChange(event: any, title: string){
let fileList: FileList = event.target.files;
this.upload_file_formdata = new FormData();
if(fileList.length > 0) {
let file = fileList[0];
this.upload_file_formdata.append('file', file, file.name)
this.upload_file_formdata.append('document.ReferenceNotes', '')
this.upload_file_formdata.append('locationCode', this.locationCode)
this.upload_file_formdata.append('sectionName', title)
// this.surveyService.AddImageToSection(this.locationCode, this.title, this.upload_file_formdata)
// .then((response) => {
// this.myConfirmModal.open()
// })
}
}

uploadFiles(title:string){
if(this.upload_file_formdata != undefined){
this.surveyService.AddImageToSection(this.locationCode, title, this.upload_file_formdata)
.then((response) => {
this.myConfirmModal.open()
})
}
}
 
 
AddImageToSection(locationCode: string, sectionName: string, fileformdata: FormData): Promise<String>{
let url = this.httpClient.getRootUrl() + 'SurveyApp/AddImageToSection/' + locationCode + '/' + sectionName;
// let url = "https://test-a.gfxsymphony.com/tacojohns/Survey/Survey/AddImageToSection";
return this.httpClient.post_file(url, fileformdata)
.toPromise()
.then((response: any) => response)
.catch(this.handleError)
}
 
 
post_file(url, data) {
let headers = new Headers();
headers.append('Content-Type', 'multipart/form-data');
headers.append('x-company-code',localStorage.getItem("company_code"));
headers.append('authorization', "Bearer "+localStorage.getItem("token"));

return this.http.post(url, data, {
headers: headers
});
}
 
 
 
.........
survey.ImageUploader = function (configObj) {
var thisObject = this;

configObj = configObj || {};

var fileUploadField = new Ext.form.FileUploadField({
allowBlank: false,
buttonCgf: { text: 'Find' },
emptyText: 'Select a file...',
fieldLabel: 'Select a file',
name: 'file'
});

var referenceField = new Ext.form.TextField({
allowBlank: true,
fieldLabel: 'File Description',
name: 'document.ReferenceNotes',
value: ''
});

var hiddenLocationField = new Ext.form.Hidden({
hidden: true,
hideLabel: true,
name: 'locationCode',
value: configObj.locationCode
});

var hiddenSectionField = new Ext.form.Hidden({
hidden: true,
hideLabel: true,
name: 'sectionName',
value: configObj.sectionName
});

var url = Survey.URL.Survey.addImageToSectionUrl();

Ext.apply(this, {
autoHeight: true,
items: [
fileUploadField,
referenceField,
hiddenLocationField,
hiddenSectionField
],
defaults: { width: 220 },
fileUpload: true,
labelWidth: 200,
standardSubmit: true,
title: 'Add Images to This Section (To upload multiple, repeat the add image process)',
url: url,
buttons: [{
text: 'Add Image',
formBind: true,
handler: function () {
//manually set the ACTION for our form
thisObject.getForm().getEl().dom.action = url;

var submitMask = new Ext.LoadMask(
thisObject.getEl(),
{ msg: 'Uploading...' }
);
submitMask.show();

//submit the form
Ext.Ajax.request({
url: url,
isUpload: true,
form: thisObject.getForm().getEl(),
success: function (response, action) {
submitMask.hide();
if (response.responseXML.title === '') {
//I guess this works for sniffing failure...

referenceField.setValue('');
fileUploadField.setValue('');
Ext.Msg.alert(
'Success!',
'Document uploaded successfully');
}
else {
Ext.Msg.alert(
'Error',
'Error uploading document:<br />' + GFX.Util.getErrorText(response)
);
}
}
});
}
}]
});

Survey.ImageUploader.superclass.constructor.apply(this, arguments);
};
Ext.extend(Survey.ImageUploader, Ext.form.FormPanel, {});
Ext.reg('survey-uploader', Survey.ImageUploader);
///////////////////////////////////////////////////
 
 
[HttpPost]
[RequireOperation(SubmitSurvey.OperationName)]
public virtual ActionResult AddImageToSection(Guid locationCode, string sectionName, HttpPostedFileBase file, DocumentDto document)
{
document.Name = file.FileName;
document.MimeType = file.ContentType;
document.ReferenceNotes = GetReferenceNotes(sectionName, document.ReferenceNotes);
var request = NewDocumentRequest.BuildRequest(CharacteristicOwnerType.Location, locationCode, file.InputStream.GetBytes(), document, RequestContext);
var response = (NewEntityResponse)RequestProcessor.Process(request);
// Must use ExtNewEntityFormSubmissionJson since the caller was a form submission
return ExtNewEntityFormSubmissionJson(response.EntityCode);
}
 
 
 
 
 
 
 
 
 
 
 

Answers (3)