Search code examples
ionic-frameworkdrupalionic4

"No filename found in "Content-Disposition" header. A file name in the format "filename=FILENAME" must be provided"


i'm trying to upload audio file from ionic 4 to drupal 8 site using REST API code is :

public uploadAudio(audioData,token,auth){
 let audio={
    uri:"public://"+new Date().getTime()+'.mp3',
    file:audioData,
    filename:new Date().getTime()+'.mp3'
  }
  let body=JSON.stringify(audio);
  let options ={ headers: new HttpHeaders({ 'Content-Type': 'application/octet-stream','Accept':'application/json','X-CSRF-Token':token ,'Authorization':'Basic '+auth ,'Content-Disposition': "file;filename=\'filename.mp3\'"}) };
  console.log(options);

 return this.httpClient.post(this.Drupal_URL+'file/upload/node/question/field_userq?_format=json',body,options);

and when i post this error shows

"No filename found in "Content-Disposition" header. A file name in the format "filename=FILENAME" must be provided"

any ideas ?


Solution

  • the solutions is to change the header to

      let options ={ headers: new HttpHeaders({ 'Content-Type': 'application/octet-stream','Accept':'application/json','X-CSRF-Token':token ,'Authorization':'Basic '+auth ,"Content-Disposition": "file; filename=\"$name.mp3\"\r"}) };