本文将为您提供关于照片未正确上传GCSAppEngine的详细介绍,我们还将为您解释照片未能成功上传的相关知识,同时,我们还将为您提供关于android–使用谷歌app-engine的GCM服务器、a
本文将为您提供关于照片未正确上传GCS App Engine的详细介绍,我们还将为您解释照片未能成功上传的相关知识,同时,我们还将为您提供关于android – 使用谷歌app-engine的GCM服务器、android – 关于Appengine的GCM XMPP?、android – 用于聊天应用程序的GCM和App Engine、angularjs – ZingChart条形图未正确生成的实用信息。
本文目录一览:- 照片未正确上传GCS App Engine(照片未能成功上传)
- android – 使用谷歌app-engine的GCM服务器
- android – 关于Appengine的GCM XMPP?
- android – 用于聊天应用程序的GCM和App Engine
- angularjs – ZingChart条形图未正确生成
照片未正确上传GCS App Engine(照片未能成功上传)
我正在上载我的upload.java servlet,以将.jpg存储到GCS。
我使用GCS客户端库而不是Google Cloud Storage API。但是我
找不到要上传照片的任何示例(doPost方法),因此我的代码无法正常工作…
发送成功(我可以在GCS上看到我的照片,大小为465.24KB),
但是当我尝试查看此照片时,我无法:
Here is my code:
upload.java servlet public void doPost(HttpServletRequest request,
HttpServletResponse response) throws IOException {
//Read the file contents from the input stream GcsService gcsService = GcsServiceFactory.createGcsService(); GcsFilename filename = new GcsFilename(BUCKETNAME, FILENAME); GcsFileOptions options = new GcsFileOptions.Builder() .mimeType("image/jpeg") .acl("public-read") .addUserMetadata("myfield1", "my field value") .build(); GcsOutputChannel writeChannel = gcsService.createOrReplace(filename, options); InputStream is = request.getInputStream(); try { copy(is, Channels.newOutputStream(writeChannel)); } finally { writeChannel.close(); is.close(); } } private void copy(InputStream input, OutputStream output) throws IOException { byte[] buffer = new byte[256]; int bytesRead = input.read(buffer); while (bytesRead != -1) { output.write(buffer, 0, bytesRead); bytesRead = input.read(buffer); } }
android code (To send photo)
HttpPost httppost = new HttpPost("adress.appengine.com/upload"); //On créé un fichier File qui contient la photo que l''on vient de prendre (Accessible via son Path) File f = new File(AccueilActivity.fileUri.getPath()); //On créé un FileBody (Contenu de notre requête http POST) contenant notre photo FileBody fileBody = new FileBody(f); //Permet de créer une requête avec plusieurs partie MultipartEntity reqEntity = new MultipartEntity(); //On ajoute notre photo avec le mot clé file. reqEntity.addPart("file", fileBody); //On set notre requête HTTP httppost.setEntity(reqEntity); //On execute notre requete HTTP Post, et on appele du coup automatiquement le servlet "uploaded", //et on met la réponse dans response. HttpResponse response = httpClient.execute(httppost); //Ici on récupère l''entête de notre réponse HTTP (Tout sauf le code réponse) HttpEntity urlEntity = response.getEntity();
Thanks in advance !
答案1
小编典典我终于(自己)找到了解决我问题的方法!我为那= D感到骄傲
The code for Android:
//Actions à réaliser en fond protected String doInBackground(String... params) { //Création d''une requête HTTP HttpClient httpClient = new DefaultHttpClient(); //On construit notre adresse Post grâce à ce que l''on vient de récupérer HttpPost httppost = new HttpPost("http://your_id.appspot.com/upload"); //On créé un fichier File qui contient la photo que l''on vient de prendre (Accessible via son Path) File f = new File(AccueilActivity.fileUri.getPath()); //Et là on essaie ! try { MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create(); entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); entityBuilder.addBinaryBody("Photo_a_uploader", f); entityBuilder.addTextBody("Type", "Type que l''utilisateur a choisi"); httppost.setEntity(entityBuilder.build()); HttpResponse response = httpClient.execute(httppost); } catch (ClientProtocolException e) { // Si on tombe dans le catch, on set notre variable à 2. e.printStackTrace(); } catch (IOException e) { // Si on tombe dans le catch, on set notre variable à 2. e.printStackTrace(); }
The code App Engine
@Override public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { //Read the file contents from the input stream GcsService gcsService = GcsServiceFactory.createGcsService(); GcsFilename filename = new GcsFilename(BUCKETNAME, FILENAME); GcsFileOptions options = new GcsFileOptions.Builder() .mimeType("image/jpg") .acl("public-read") .addUserMetadata("myfield1", "my field value") .build(); GcsOutputChannel writeChannel = gcsService.createOrReplace(filename, options); ServletFileUpload upload = new ServletFileUpload(); res.setContentType("text/plain"); try { FileItemIterator iterator = upload.getItemIterator(req); while (iterator.hasNext()) { FileItemStream item = iterator.next(); InputStream stream = item.openStream(); if (item.isFormField()) { log.warning("Champs texte avec id: " + item.getFieldName()+", et nom: "+Streams.asString(stream)); } else { log.warning("Nous avons un fichier à uploader : " + item.getFieldName() + ", appelé = " + item.getName()); // You now have the filename (item.getName() and the // contents (which you can read from stream). Here we just // print them back out to the servlet output stream, but you // will probably want to do something more interesting (for // example, wrap them in a Blob and commit them to the // datastore). // Open a channel to write to it byte[] bytes = ByteStreams.toByteArray(stream); try { writeChannel.write(ByteBuffer.wrap(bytes)); } finally { writeChannel.close(); stream.close(); } } } } catch (FileUploadException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
我希望这些示例可以帮助您使用App Engine和Google云存储!
android – 使用谷歌app-engine的GCM服务器
提前致谢!
解决方法
android – 关于Appengine的GCM XMPP?
解决方法
OTOH,您可以使用Outgoing Socket API然后实现XMPP协议.
android – 用于聊天应用程序的GCM和App Engine
用于下游:https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/GcmEndpoints
对于上游:https://developers.google.com/cloud-messaging/upstream
解决方法
angularjs – ZingChart条形图未正确生成
html file
<zingchart id="timesheet-bar-chart" zc-json="myObj"></zingchart>
in controller.js
$scope.myObj = { "type": "bar","utc": true,"plotarea":{ "margin":'dynamic' },"plot":{ "stacked":true,"stack-type":"normal" /* Optional specification */ },"scaleX":{ "transform":{ "type":"date","all":"%d %M","item": { "visible":false } },},"series":[{ "values": $scope.barValues,"backgroundColor":"#f15662" }] }; zingchart.render({ id : 'timesheet-bar-chart',height: 400,width: "100%" });
在$scope.barValues中,数据以下面的格式动态添加
[[[1478025000000,10],[1477938600000,20],[1478889000000,30]]]
我没有得到任何错误.生成的栏不是格式.请帮帮我,我是第一次使用ZingChart库.
解决方法
scale docs
token docs
条形偏移是非线性数据的乘积.由于非线性数据,条形尺寸现在被挤压得更小.这是由于尺寸随着时间的推移.您可以通过添加缩放(单击并拖动以缩放)来查看条形将增加大小.
zooming docs
var myConfig = { "type": "bar","scaleX":{ "zooming":true,"transform":{ "type":"date","all":"%d %M %Y<br> %h:%i:%s","series":[{ "values": [[1478025000000,30]],"backgroundColor":"#f15662" }] }; zingchart.render({ id: 'myChart',data: myConfig,height: '100%',width: '100%' });
html,body { height:100%; width:100%; margin:0; padding:0; } #myChart { height:100%; width:100%; min-height:150px; }
<!DOCTYPE html> <html> <head> <script src= "https://cdn.zingchart.com/zingchart.min.js"></script> </head> <body> <div id="myChart"></div> </body> </html>
您可以通过使用bar-width属性设置固定大小来避免这种情况.
plot docs
var myConfig = { "type": "bar","plot":{ "bar-width": 30,"stacked":true,body { height:100%; width:100%; margin:0; padding:0; } #myChart { height:100%; width:100%; min-height:150px; }
<!DOCTYPE html> <html> <head> <!--Assets will be injected here on compile. Use the assets button above--> <script src= "https://cdn.zingchart.com/zingchart.min.js"></script> </head> <body> <div id="myChart"></div> </body> </html>
我们今天的关于照片未正确上传GCS App Engine和照片未能成功上传的分享就到这里,谢谢您的阅读,如果想了解更多关于android – 使用谷歌app-engine的GCM服务器、android – 关于Appengine的GCM XMPP?、android – 用于聊天应用程序的GCM和App Engine、angularjs – ZingChart条形图未正确生成的相关信息,可以在本站进行搜索。
本文标签: