發(fā)現(xiàn)問(wèn)題
最近給服務(wù)器上了https,但是遇到了一個(gè)問(wèn)題:
在上傳文件后(通過(guò)https接口),所獲取到的上傳地址卻是http的:
var file = new Parse.File('aa.txt', {base64:'ss'});
file.save().then(f => {
console.log(f.url());
});
經(jīng)過(guò)仔細(xì)檢查各種配置,還是一樣的問(wèn)題。
解決問(wèn)題
自然是先上github搜一下issues,果不其然有人已經(jīng)遇到且提交了解決代碼:
https://github.com/parse-community/Parse-SDK-JS/pull/192/files#diff-67ccbb663bacb4c7556216ddb313067cR145
他的辦法并不是從服務(wù)端去解決的,而是在客戶端sdk的file.url()方法上,加入一個(gè)可選配置,如果傳入了forceSecure=true參數(shù),則直接把url地址轉(zhuǎn)換成https的。
所以我們就直接在客戶端上修復(fù)以下吧:
var file_url = parseFile.url({ forceSecure: true });