Skip to content

Commit 6f32afe

Browse files
winddiesnighca
winddies
authored andcommitted
Fix protocol issue (#357)
1 parent 02638c2 commit 6f32afe

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "qiniu-js",
33
"jsName": "qiniu",
4-
"version": "2.2.0",
4+
"version": "2.2.1",
55
"private": false,
66
"description": "Javascript SDK for Qiniu Resource (Cloud) Storage AP",
77
"main": "dist/qiniu.min.js",

src/utils.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export function getDomainFromUrl (url) {
201201

202202
// 构造区域上传url
203203
export function getUploadUrl(config, token) {
204-
let protocol = window.location.protocol;
204+
let protocol = getAPIProtocol();
205205
if (config.region != null){
206206
let upHosts = regionUphostMap[config.region];
207207
let host = config.useCdnDomain ? upHosts.cdnUphost : upHosts.srcUphost;
@@ -214,6 +214,13 @@ export function getUploadUrl(config, token) {
214214
});
215215
}
216216

217+
function getAPIProtocol() {
218+
if (window.location.protocol === "http:") {
219+
return "http:";
220+
}
221+
return "https:";
222+
}
223+
217224
function getPutPolicy(token) {
218225
let segments = token.split(":");
219226
let ak = segments[0];
@@ -226,7 +233,7 @@ function getPutPolicy(token) {
226233
function getUpHosts(token) {
227234
try {
228235
let putPolicy = getPutPolicy(token);
229-
let url = window.location.protocol + "//api.qiniu.com/v2/query?ak=" + putPolicy.ak + "&bucket=" + putPolicy.bucket;
236+
let url = getAPIProtocol() + "//api.qiniu.com/v2/query?ak=" + putPolicy.ak + "&bucket=" + putPolicy.bucket;
230237
return request(url, { method: "GET" });
231238
} catch (e) {
232239
return Promise.reject(e);

0 commit comments

Comments
 (0)