简体   繁体   中英

Drop n' swap text chunks with GAE Blobstore API

I am designing a GAE app that will allow a user to upload a PDF file, whereby I'll save it off to the GAE Blobstore.

I need the ability to "drop n' swap" chunks of text in these blobstored files. That is, I need the ability to cherry pick a particular sentence out of the file (stored in the Blobstore), and replace it with different text.

Say I have a PDF file, and I know that starting at the 505th byte/character in the file, there is the sentence:

The woods are lovely, dark and deep.

And I want to replace (drop n' swap) that sentence with:

But I have promises to keep.

Then I know that I want to replace bytes 505 through 541 ( The woods are lovely, dark and deep. ) with my new string.

So I ask: is this possible? I see that the Blobstore API allows you to read a specific segment of characters from a stored blob:

// Now contains: "The woods are lovely, dark and deep."
String toDropNSwap = blobStoreService.fetchData(blobKey, 505, 541);

toDropNSwap = "But I have promises to keep.";

// This doesn't exist, just an example:
blobstoreService.dropAndSwap(505, 541, toDropNSwap);

But I don't see how I can replace a segment of bytes with another segment of bytes, especially if the new segment is a different size. And one more thing: I'll be working with files up to 20MB in size. Thanks in advance.

Blobs are immutable :

Blobs can't be modified after they're created, though they can be deleted. Each blob has a corresponding blob info record, stored in the datastore, that provides details about the blob, such as its creation time and content type. You can use the blob key to fetch blob info records and query their properties.

So what you are looking for is not possible. You will have to delete and create a new blob instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM