iam new sencha touch。我需要將圖像轉換爲base64字符串,iam上傳圖像,並且iam獲取圖像的fulll路徑,但是iam無法將圖像轉換爲base64字符串。如何在sencha touch中將圖像(使用圖像路徑)轉換爲base64字符串?
plz幫我解決這個問題。 請確保iam在sencha touch中提問
iam new sencha touch。我需要將圖像轉換爲base64字符串,iam上傳圖像,並且iam獲取圖像的fulll路徑,但是iam無法將圖像轉換爲base64字符串。如何在sencha touch中將圖像(使用圖像路徑)轉換爲base64字符串?
plz幫我解決這個問題。 請確保iam在sencha touch中提問
如何訪問這些文件?圖像來自哪裏?如果他們來自相機或照相館,那麼Phonegap是獲得它們的最佳方式。在這種情況下,PG解決Base64編碼。如果你試圖用純js解決它,那麼你需要做更多的工作。 Sencha不提供base64編碼功能。所以如果你爲你的項目添加一些功能,最好的選擇。網上有很多資源如何在javascript中進行base64編碼。例如。看到這裏的討論Base64 encoding and decoding in client-side Javascript
下面的代碼片段可以幫助你上傳圖片,並得到的base64數據URI
在你看來,你應該有煎茶觸摸以下的FileField組件
Ext.define('MyApp.view.Main', {
extend: 'Ext.form.Panel',
xtype: 'main',
requires: [
'Ext.TitleBar',
'Ext.Video'
],
config: {
tabBarPosition: 'bottom',
items: [
{
xtype: 'filefield',
id: 'idfilefieldSample',
name: 'filefieldSample',
accept: 'image'
},
]
}
});
和您的控制器是這樣的:
Ext.define('MyApp.controller.MainController', {
extend: 'Ext.app.Controller',
config:{
control:{
'filefield[name=filefieldSample]': {
change: 'onChangefilefield',
},
}
},
onChangefilefield: function(filefield, newData, oldData, eOpts)
{
var filesSelected = Ext.getCmp('idfilefieldSample').getComponent().input.dom.files;
if (filesSelected.length > 0)
{
var fileToLoad = filesSelected[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var srcData = fileLoadedEvent.target.result;
console.log(srcData);
}
fileReader.readAsDataURL(fileToLoad);
}
},
});
是否使用薩斯樣式? – 2012-03-30 23:14:25