如何使用离子角度将图像上传到谷歌驱动器

问题描述 投票:0回答:1

如何使用离子角度(Android)将图像上传到谷歌硬盘。我需要将我的离子应用程序连接到谷歌驱动器。从应用程序,图像将保存到谷歌驱动器。

angular image ionic-framework upload drive
1个回答
0
投票

您应该制作一个将图像放入Google云端硬盘的后端服务。并将您的应用与此服务相关联。

这种情况的后端代码示例:

@RequestMapping(value="/savefile",method=RequestMethod.POST)  
public ModelAndView upload(@RequestParam CommonsMultipartFile file, HttpSession session) {  
    String path = session.getServletContext().getRealPath("/");  
    String filename = file.getOriginalFilename();  

    System.out.println(path+" "+filename);  
    try {  
        byte barr[] = file.getBytes();  

        // this code put the file in the path 
        BufferedOutputStream bout = new BufferedOutputStream(  
             new FileOutputStream(path + "/" + filename));  
        bout.write(barr);  
        bout.flush();  
        bout.close();  
    } catch(Exception e) {
        System.out.println(e);
    }  

    return new ModelAndView("upload-success", "filename", path + "/" + filename);  
}

您应该将将文件放入文件夹的代码更改为将文件存储在Google云端硬盘中的其他代码。

您应用中的代码:

const httpOptions = {
  headers: new HttpHeaders({
    'Content-Type':  'application/json',
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Methods': 'GET, PUT, POST, DELETE'
  })
};

uploadImage(url: string, param: any): Observable<any> {
  const body = JSON.stringify(param);
  console.log(body);
  return this.http
    .post(url, body, httpOptions);
}

uploadImage('Url to the back-service', image)
  .subscribe(
    result => {
      console.log('Image uploaded' + result);
    },
    error => console.log(error)
 );
© www.soinside.com 2019 - 2024. All rights reserved.