nonetype' object has no attribute 'decode' error when i upload the image to database

和自甴很熟 提交于 2020-01-30 11:42:26

问题


i am new to ionic4/angular4.i need to upload the profile pic to database.i wrote code but i don't know whether it is correct or not and when i am uploading it i am getting the above mentioned error. backed i am using Django and sorry for the bad indentation.i just beginner to programming.

.ts

 async sendPictureToSomewhere() {
const fileuri = await this.getPicture();
const blobinfo = await this.b64toBlob(fileuri);
await this.upload(blobinfo);
alert("done");
}

 async getPicture() {
const options: CameraOptions = {
  quality: 100,
  destinationType: this.camera.DestinationType.FILE_URI,
  encodingType: this.camera.EncodingType.JPEG,
  mediaType: this.camera.MediaType.PICTURE
  // targetWidth: 200
};

let fileuri = await this.camera.getPicture(options);
return fileuri;
}

 b64toBlob(_imagePath) {
 return new Promise((resolve, reject) => {
  let fileName = "";
  this.file
    .resolveLocalFilesystemUrl(_imagePath)
    .then(fileEntry => {
      let { name, nativeURL } = fileEntry;

      // get the path..
      let path = nativeURL.substring(0, nativeURL.lastIndexOf("/"));
      console.log("path", path);
      console.log("fileName", name);

      fileName = name;

      // we are provided the name, so now read the file into
      // a buffer
      return this.file.readAsArrayBuffer(path, name);
    })
    .then(buffer => {
      // get the buffer and make a blob to be saved
      let imgBlob = new Blob([buffer], {
        type: "image/jpeg"
      });
      console.log(imgBlob.type, imgBlob.size);
      resolve({
        fileName,
        imgBlob
      });
    })
    .catch(e => reject(e));
  });
 }

 upload(_Blobinfo) {
  this.profileService.postInfluencerProfile(_Blobinfo, null, 
 null).subscribe(
  response => {
    console.log(response);
  },
  (error: MavinError) => {
    if (error instanceof NotFoundError) {
      alert("Not found");
    } else {
      console.log(error);
    }
  }
);
 }
 }

来源:https://stackoverflow.com/questions/56870631/nonetype-object-has-no-attribute-decode-error-when-i-upload-the-image-to-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!