Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Base64 appcelerator钛基64编码blob对象_Base64_Blob_Titanium_Appcelerator_Encode - Fatal编程技术网

Base64 appcelerator钛基64编码blob对象

Base64 appcelerator钛基64编码blob对象,base64,blob,titanium,appcelerator,encode,Base64,Blob,Titanium,Appcelerator,Encode,我正在使用appcelerator titanium(sdk 1.6.2)开发一个移动(iphone/android)应用程序。 在应用程序中的某个点,用户选择一个应该在imageView中显示的图像,进行base64编码,然后上传到我的服务器。 问题是照片库的成功事件将所选图像作为blob对象返回,而Titanium.Utils.base64encode方法只接受字符串值! 有没有办法将Tianium.Blob对象转换为字符串 以下是代码片段: var imageView = Titanium

我正在使用appcelerator titanium(sdk 1.6.2)开发一个移动(iphone/android)应用程序。 在应用程序中的某个点,用户选择一个应该在imageView中显示的图像,进行base64编码,然后上传到我的服务器。 问题是照片库的成功事件将所选图像作为blob对象返回,而Titanium.Utils.base64encode方法只接受字符串值! 有没有办法将Tianium.Blob对象转换为字符串

以下是代码片段:

var imageView = Titanium.UI.createImageView({
height:200,
width:200,
top:20,
left:10,
backgroundColor:'#999'
});

Titanium.Media.openPhotoGallery({

success:function(event)
{
    var cropRect = event.cropRect;
    var image = event.media;//blob object

    // set image view
    Ti.API.debug('Our type was: '+event.mediaType);
    if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
    {
        imageView.image = image;// this works
        var imgStr=Ti.Utils.base64encode(image);// doesn't work because 'image' has to be a string!, but how?
    }
    else
    {

    }

    Titanium.API.info('PHOTO GALLERY SUCCESS cropRect.x ' + cropRect.x + ' cropRect.y ' + cropRect.y  + ' cropRect.height ' + cropRect.height + ' cropRect.width ' + cropRect.width);

},
allowEditing:true,
popoverView:popoverView,
arrowDirection:arrowDirection,
mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
});
谢谢,

var imgStr=Ti.Utils.base64encode(image.toString());

.toString()将某些内容转换为字符串表示形式

我刚刚发布了一些模块代码来执行此转换,我知道appcelerator提供了一个补丁,但该模块现在可能对您有用

这对我很有效

var image = event.media;
var imgStr = Ti.Utils.base64encode(image).toString();