在离子应用程序中将图像和json数据发送到服务器
我正在开发一个android应用程序。 在我的控制器中,我试图将图像和JSON发送到服务器。
我使用相机插件捕获图像,然后使用$cordovaFileTransfer将图像和json对象发送到服务器。 该服务器支持多种形式的请求。
我做的是这样的:
// Destination URL
var url = "http://example.gajotres.net/upload/upload.php";
//File for Upload
var targetPath = "myImage.jpg";
// File name only
var filename = targetPath.split("/").pop();
var options = { fileKey: "file", fileName: filename, chunkedMode: false, mimeType: "image/jpg" }
var params = {};
params.info = {
aaaa : "zeze",
zeze : "aaza",
info = {
ere: 45,
azeae: "ezrz"
}
}
options.params = params;
$cordovaFileTransfer.upload(url, targetPath, options).then(function (result) {
console.log("SUCCESS: " + JSON.stringify(result.response)); }, function (err) { console.log("ERROR: " + JSON.stringify(err)); }, function (progress) { // PROGRESS HANDLING GOES HERE });
服务器端我检查收到的数据,一切都很好,但形式“信息”没有内容类型:应用程序/ JSON,所以服务器不能解释它。 我需要发送一个多形式请求并为每个表单指定内容类型。
你有解决方案吗?
谢谢
链接地址: http://www.djcxy.com/p/5351.html上一篇: Send image and json data to server in a ionic application
下一篇: how to use a base64
