when i remove the inputream, everything works but the following error
surfaces when i try to retrieve the image ie serve it
Invalid Key PB: no elements.
int contentLength=BLOB_MAX_SIZE;
byte[] data = new byte[contentLength];
int bytesRead = 0;
int offset = 0;
while (offset < contentLength && in!=null) {
bytesRead = in.read(data, offset, data.length - offset);
if (bytesRead == -1)
break;
offset += bytesRead;
}
//in.close();
//create POST to upload to blogstore
BlobstoreService blobstoreService
=BlobstoreServiceFactory.getBlobstoreService();
String uploadURL = blobstoreService.createUploadUrl("/uploadblob");
//add host if in dev mode
if (uploadURL.indexOf("http") == -1)
uploadURL = "http://127.0.0.1:8888" + uploadURL;
URL url = new URL(uploadURL);
// create a boundary string
String boundary = MultiPartFormOutputStream.createBoundary();
URLConnection urlConn =MultiPartFormOutputStream.createConnection(url);
urlConn.setReadTimeout(15000);
urlConn.setRequestProperty("Accept", "*/*");
urlConn.setRequestProperty("Content-Type",
MultiPartFormOutputStream.getContentType(boundary));
// set some other request headers...
urlConn.setRequestProperty("Connection", "Keep-Alive");
urlConn.setRequestProperty("Cache-Control", "no-cache");
// no need to connect because getOutputStream() does it
MultiPartFormOutputStream out1 = new
MultiPartFormOutputStream(urlConn.getOutputStream(), boundary);
// write a text field element - This should be removed - left
over from multipart library demo code
out1.writeField("myText", "text field text");
// write bytes directly
out1.writeFile("myFile", contentType, tileBlob, data);
out1.close();
// read response from server
BufferedReader responseIn = new BufferedReader(new
InputStreamReader(urlConn.getInputStream()));
StringBuilder redirectResponse = new StringBuilder();
String line="";
while((line = responseIn.readLine()) != null) {
redirectResponse.append(line);
}
//in.close();
//extract the blobstore key from the response
// String blogKeyStr
=Utilitie.findSubString(redirectResponse.toString(), "blogkey =
'","'</H1>");
String blogKeyStr =redirectResponse.toString();
if (blogKeyStr == null || blogKeyStr.equals("FAILED"))
throw new IOException("Failed to upload image blob");
out.print(blogKeyStr);
}
On Mon, Nov 22, 2010 at 7:10 PM, acellam guy <[email protected]> wrote:
> hey tim, i have tried your code but some of the variables are not declared
> and am having a nightmare
>
>
> On Mon, Nov 22, 2010 at 5:04 PM, timwhunt <[email protected]> wrote:
>
>> So to be clear, yes you can post the data from your code to the
>> blobstore, but you are limited by the 1mb request limit.
>>
>> I've previously posted some sample code in another thread:
>>
>> http://groups.google.com/group/google-appengine-java/browse_thread/thread/2bea1295a3f542de/854ea95dcd986dab
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google App Engine" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<google-appengine%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/google-appengine?hl=en.
>>
>>
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.