GVKun编程网logo

照片未正确上传GCS App Engine(照片未能成功上传)

26

本文将为您提供关于照片未正确上传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(照片未能成功上传)

照片未正确上传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 – 使用谷歌app-engine的GCM服务器

我刚刚为GCM客户端和服务器端实现了SDK示例.我使用NetBeans(Glass Fish)作为我的服务器端而 Eclipse作为我的客户端( Android)没有任何问题.我现在想探索使用Google App Engine作为我的服务器端.我从SDK下载了示例,但无法将其编译并运行….是否有任何关于此的教程,如常规服务器客户端GCM?
提前致谢!

解决方法

您可能希望在此 Using App Engine for Java上花费很多时间,这是Google的GCM文档的一部分.这是另一篇关于基于GAE的GCM服务器的博客文章: http://www.andro.lt/2012/11/google-cloud-messaging-for-android.html

android – 关于Appengine的GCM XMPP?

android – 关于Appengine的GCM XMPP?

谷歌刚刚宣布使用xmpp协议向IO13发布GCM的新api.是否可以将这个api与appengine一起使用?它似乎不适用于appengine的XMPP支持,但可能与新的套接字api一起使用.这可以从前端,后端或两者完成吗?

解决方法

目前的GAE XMPP支持无法做到这一点.问题是用户/服务器寻址:GAE XMPP API向通过电子邮件地址定义的用户发送消息.然后,它为XMPP服务器SRV记录执行DNS查找(例如,使用dig srv _xmpp-server._tcp.gmail.com short查找@ gmail.com地址的XMPP服务器).这不是GCM CCS的工作原理 – 您必须连接到固定服务器.

OTOH,您可以使用Outgoing Socket API然后实现XMPP协议.

android – 用于聊天应用程序的GCM和App Engine

android – 用于聊天应用程序的GCM和App Engine

我打算制作一个聊天应用程序,用户可以通过该应用程序发送和接收文本和媒体 – 音频,图像和视频.为简单起见,我决定在GCM中使用app引擎.使用提供的示例指南和 Android Studio模板,使用GCM执行下游工作似乎很有效(对于短信).当我尝试上游时,我没有收到回复消息.可能这是非常微不足道的,但有人可以指点我一个很好的教程或书.有什么建议?

用于下游:https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/GcmEndpoints
对于上游:https://developers.google.com/cloud-messaging/upstream

解决方法

我不得不补充一下 @ApiMethod(name =“sendMessage”) 通过Studio模板生成的MessagingEndpoint类中的sendMessage方法.之后我能够使用sendMessage api将消息发送回链接到GCM的app引擎服务器,该消息也回显给我的设备.

angularjs – ZingChart条形图未正确生成

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库.

enter image description here

解决方法

你的条形图生成得很好.条形图从标签上看是因为您正在绘制[[]](数组数组).如果您查看绘制的时间戳,则确实没有在11月4日准确绘制条形图.如果您要引用标签本身,则可以确定all属性显示标签的内容.您可以将步骤属性设置为更线性或使用缩放.

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条形图未正确生成的相关信息,可以在本站进行搜索。

本文标签: