1MB quota limit for a blobstore object in Google App Engine?

前端 未结 3 575
野趣味
野趣味 2020-12-17 00:47

I\'m using App Engine (version 1.4.3) direct write the blobstore in order to save images. when I try to store an image which is larger than 1MB I get the following Exceptio

3条回答
  •  无人及你
    2020-12-17 01:10

    As Brummo suggested above if you split it into chunks < 1MB it works. Here's some code.

    public BlobKey putInBlobStoreString(String fileName, String contentType, byte[] filebytes) throws IOException {
        // Get a file service
        FileService fileService = FileServiceFactory.getFileService();
        AppEngineFile file = fileService.createNewBlobFile(contentType, fileName);
        // Open a channel to write to it
        boolean lock = true;
        FileWriteChannel writeChannel = null;
        writeChannel = fileService.openWriteChannel(file, lock);
        // lets buffer the bitch
        BufferedInputStream in = new BufferedInputStream(new ByteArrayInputStream(filebytes));
        byte[] buffer = new byte[524288]; // 0.5 MB buffers
        int read;
        while( (read = in.read(buffer)) > 0 ){ //-1 means EndOfStream
            ByteBuffer bb = ByteBuffer.wrap(buffer);
            writeChannel.write(bb);
        }
        writeChannel.closeFinally();
        return fileService.getBlobKey(file);
    }
    

提交回复
热议问题