简体   繁体   English

如何使用JSON-通过PhoneGap(iPhone)进行JQuery将捕获的照片上传到REST界面?

[英]How to upload a captured photo to REST interface using JSON - JQuery by PhoneGap (iPhone)?

My application asks from the user to capture an photo and then upload it to the server if the user is online. 我的应用程序要求用户捕获照片,然后将其上传到服务器(如果用户在线)。 The code for the photo capture I took from PhoneGap API . 我从PhoneGap API中获取的照片捕获代码。 How can I use the imgURL to upload it to the REST interface using Json and Jquery mobile? 我如何使用Json和Jquery mobile将imgURL上载到REST接口?

The code I have up to now is: 我到目前为止的代码是:

function onPhotoDataSuccess(imageData) {
// Uncomment to view the base64 encoded image data
// console.log(imageData);

// Get image handle
//
var smallImage = document.getElementById('smallImage');

// Unhide image elements
//
smallImage.style.display = 'block';

// Show the captured photo
// The inline CSS rules are used to resize the image
//
smallImage.src = "data:image/jpeg;base64," + imageData;

} }

Again, it is the same code taken from the PhoeGap API... I appreciate any help!... 同样,它与从PhoeGap API中提取的代码相同...感谢您的帮助!...

Not sure if I understand your question correctly. 不知道我是否正确理解您的问题。

You should have your rest url and data structure (in JSON) the endpoint expects. 您应该具有端点期望的其余URL和数据结构(JSON)。 Once you have the base64 encoded string Use JSON library for packing JSON data and then send it to the service using jquery.ajax(). 有了base64编码的字符串后,请使用JSON库包装JSON数据,然后使用jquery.ajax()将其发送到服务

Edited to include the post code 编辑以包括邮政编码

$.ajax({
  type: 'POST',
  url: yoururl,
  data: jsondata,
  success: success,
  dataType: dataType
});

Content type will usually be 内容类型通常为

contentType: "application/json; charset=utf-8" 

and datatype will be 和数据类型将是

dataType: 'json'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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