简体   繁体   English

我如何在Titanium(Android)中以jpg或png格式在服务器上上传图像?

[英]How I upload Image on server in jpg or png format in Titanium (Android)?

I want to upload image to server for my phone gallery. 我想将图片上传到我的手机图库的服务器。

I have done with iOS device this is working well. 我已经完成iOS设备,这是运作良好。 But, in Android Device have problem. 但是,在Android设备中有问题。

I take image from my Device gallery and post on server. 我从我的设备库中获取图像并在服务器上发布。 This is upload successfully. 这是成功上传的。 after this i see on Server. 在此之后,我在服务器上看到。

whose Image uploaded by Android device, this is in .txt format. 其图像由Android设备上传,采用.txt格式。 (iOS have working well). (iOS运行良好)。

How i remove the problem.Please help me i show you my coding structure. 我如何删除问题。请帮助我,我告诉你我的编码结构。

 Ti.API.info("success! event: " + JSON.stringify(event));
        var image = event.media;

        var abc = event.media.imageAsResized(400 , 400);


        Ti.API.info(abc.height +" x "+ abc.width);
        alert(abc.height +" x "+ abc.width);

       var xhr = Titanium.Network.createHTTPClient();

        xhr.onerror = function(e)
        {
            Ti.API.info('IN ERROR ' + e.error);
            alert("error");
        };
        xhr.onload = function()
        {
            Ti.API.info('IN ONLOAD ' + this.status + ' readyState ' + xhr.responseText);
            alert("IN ONLOAD " + this.status + " readyState " + this.readyState + "re " +xhr.responseText);

        };


         xhr.open('POST','http://reviewprototypes.com/kishan/filetest.php');
        xhr.send({file:abc});
 },
                cancel : function() {

                    alert("Cancel Library ");
                },
                error : function(error) {

                    alert("Error Massage "+error);
                },
                allowImageEditing:true,

               });

Any suggestion is appreciated.. Thanks in Advance. 任何建议表示赞赏..在此先感谢。

Try setting the POST requests content-type header to Content-type: multipart/form-data , other than that I can't really suggest anything :( 尝试将POST请求内容类型标题设置为Content-type: multipart/form-data ,除此之外我无法真正建议:(

Dom 大教堂

I have solve my problem from this reference Example . 我从这个参考例子中解决了我的问题。 Try this one. 试试这个吧。

try https : 尝试https
xhr.open('POST',' https ://reviewprototypes.com/kishan/filetest.php'); xhr.open('POST',' https ://reviewprototypes.com/kishan/filetest.php');

Snowmed. Snowmed。

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

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