如何将App Engine存储桶的URL添加到数据库Java

时间:2018-11-21 03:35:33

标签: spring-boot google-app-engine google-cloud-platform bucket

但是此代码可以正常工作,但仅返回App Engine存储桶的上传文件网址?关于如何将url添加到数据库中的任何想法?

@RestController
@RequestMapping("/api")
public class CloudStorageHelper  {
    Credentials credentials = GoogleCredentials.fromStream(new FileInputStream("C:\\Users\\sachinthah\\Downloads\\MCQ project -1f959c1fc3a4.json"));
    Storage storage = StorageOptions.newBuilder().setCredentials(credentials).build().getService();

    public CloudStorageHelper() throws IOException {
    }
    @SuppressWarnings("deprecation")
    @RequestMapping(method = RequestMethod.POST, value = "/imageUpload112")
    public String uploadFile(@RequestParam("fileseee")MultipartFile fileStream)
            throws IOException, ServletException {

        String bucketName = "mcqimages";
        checkFileExtension(fileStream.getName());
        DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
        DateTime dt = DateTime.now(DateTimeZone.UTC);
        String dtString = dt.toString(dtf);
        String fileName = fileStream.getOriginalFilename()  ;

        BlobInfo blobInfo =
                storage.create(
                        BlobInfo
                                .newBuilder(bucketName, fileName)
                                .setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER))))
                                .build(),
                        fileStream.getInputStream()
                );
        System.out.println(blobInfo.getMediaLink());

        return blobInfo.getMediaLink()+",";
    }

0 个答案:

没有答案