-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 294a9a9
Showing
28 changed files
with
9,217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
node_modules | ||
/samples/simple-app/index/config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 腾讯云 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# cos-wx-sdk-v5 | ||
|
||
微信小程序 sdk for [腾讯云对象存储服务](https://www.qcloud.com/product/cos) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//app.js | ||
App({ | ||
onLaunch: function () { | ||
//调用API从本地缓存中获取数据 | ||
var logs = wx.getStorageSync('logs') || []; | ||
logs.unshift(Date.now()) | ||
wx.setStorageSync('logs', logs) | ||
}, | ||
getUserInfo:function(cb){ | ||
var that = this | ||
if(this.globalData.userInfo){ | ||
typeof cb == "function" && cb(this.globalData.userInfo); | ||
}else{ | ||
//调用登录接口 | ||
wx.login({ | ||
success: function () { | ||
wx.getUserInfo({ | ||
success: function (res) { | ||
that.globalData.userInfo = res.userInfo; | ||
typeof cb == "function" && cb(that.globalData.userInfo); | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
}, | ||
globalData:{ | ||
userInfo:null | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"pages":[ | ||
"pages/index/index" | ||
], | ||
"window":{ | ||
"backgroundTextStyle":"light", | ||
"navigationBarBackgroundColor": "#fff", | ||
"navigationBarTitleText": "COS 小程序 SDK DEMO", | ||
"navigationBarTextStyle":"black" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/**app.wxss**/ | ||
.container { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
AppId: '1250000000', | ||
SecretId: 'AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | ||
SecretKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', | ||
Bucket: 'wx', | ||
Region: 'ap-guangzhou' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
var COS = require('../lib/cos-wx-sdk-v5'); | ||
var config = require('./config'); | ||
|
||
var cos = new COS({ | ||
AppId: config.AppId, | ||
getAuthorization: function (params, callback) {//获取签名 必填参数 | ||
var authorization = COS.getAuthorization({ | ||
SecretId: config.SecretId, | ||
SecretKey: config.SecretKey, | ||
Method: params.Method, | ||
Key: params.Key | ||
}); | ||
callback(authorization); | ||
} | ||
}); | ||
|
||
// 回调统一处理函数 | ||
var requestCallback =function (err, data) { | ||
console.log(err || data); | ||
if (err && err.error) { | ||
wx.showModal({title: '返回错误', content: '请求失败:' + err.error.Message + ';状态码:' + err.statusCode, showCancel: false}); | ||
} else if (err) { | ||
wx.showModal({title: '请求出错', content: '请求出错:' + err + ';状态码:' + err.statusCode, showCancel: false}); | ||
} else { | ||
wx.showToast({title: '请求成功', icon: 'success', duration: 3000}); | ||
} | ||
}; | ||
|
||
// 展示的所有接口 | ||
var dao = { | ||
// Service | ||
getService: function () { | ||
cos.getService(requestCallback); | ||
}, | ||
// Bucket | ||
headBucket: function () { | ||
cos.headBucket({Bucket: config.Bucket, Region: config.Region}, requestCallback); | ||
}, | ||
getBucket: function () { | ||
cos.getBucket({Bucket: config.Bucket, Region: config.Region}, requestCallback); | ||
}, | ||
deleteBucket: function () { | ||
cos.deleteBucket({Bucket: config.Bucket, Region: config.Region}, requestCallback); | ||
}, | ||
getBucketACL: function () { | ||
cos.getBucketAcl({Bucket: config.Bucket, Region: config.Region}, requestCallback); | ||
}, | ||
putBucketACL: function () { | ||
cos.putBucketAcl({Bucket: config.Bucket, Region: config.Region, ACL: 'public-read'}, requestCallback); | ||
}, | ||
getBucketCors: function () { | ||
cos.getBucketCors({Bucket: config.Bucket, Region: config.Region}, requestCallback); | ||
}, | ||
putBucketCors: function () { | ||
cos.putBucketCors({Bucket: config.Bucket, Region: config.Region, | ||
CORSRules: [{ | ||
"AllowedOrigin": ["*"], | ||
"AllowedMethod": ["GET", "POST", "PUT", "DELETE", "HEAD"], | ||
"AllowedHeader": ["*"], | ||
"ExposeHeader": ["ETag"], | ||
"MaxAgeSeconds": "5" | ||
}] | ||
}, requestCallback); | ||
}, | ||
putBucketPolicy: function () { | ||
cos.putBucketPolicy({Bucket: config.Bucket, Region: config.Region}, requestCallback); | ||
}, | ||
deleteBucketCORS: function () { | ||
cos.deleteBucketCors({Bucket: config.Bucket, Region: config.Region}, requestCallback); | ||
}, | ||
getBucketLocation: function () { | ||
cos.getBucketLocation({Bucket: config.Bucket, Region: config.Region}, requestCallback); | ||
}, | ||
getBucketPolicy: function () { | ||
cos.getBucketPolicy({Bucket: config.Bucket, Region: config.Region}, requestCallback); | ||
}, | ||
getBucketTagging: function () { | ||
cos.getBucketTagging({Bucket: config.Bucket, Region: config.Region}, requestCallback); | ||
}, | ||
putBucketTagging: function () { | ||
cos.putBucketTagging({Bucket: config.Bucket, Region: config.Region}, requestCallback); | ||
}, | ||
deleteBucketTagging: function () { | ||
cos.deleteBucketTagging({Bucket: config.Bucket, Region: config.Region}, requestCallback); | ||
}, | ||
headObject: function () { | ||
cos.headObject({Bucket: config.Bucket, Region: config.Region}, requestCallback); | ||
}, | ||
getObject: function () { | ||
cos.getObject({Bucket: config.Bucket, Region: config.Region}, requestCallback); | ||
}, | ||
deleteObject: function () { | ||
cos.deleteObject({Bucket: config.Bucket, Region: config.Region, Key: '1.png'}, requestCallback); | ||
}, | ||
getObjectACL: function () { | ||
cos.getObjectAcl({Bucket: config.Bucket, Region: config.Region, Key: '1.png'}, requestCallback); | ||
}, | ||
putObjectACL: function () { | ||
cos.putObjectAcl({Bucket: config.Bucket, Region: config.Region, Key: '1.png'}, requestCallback); | ||
}, | ||
optionsObject: function () { | ||
cos.optionsObject({Bucket: config.Bucket, Region: config.Region, Key: '1.png'}, requestCallback); | ||
}, | ||
putObjectCopy: function () { | ||
cos.putObjectCopy({Bucket: config.Bucket, Region: config.Region, Key: '1.png'}, requestCallback); | ||
}, | ||
// Object | ||
postObject: function () { | ||
wx.chooseImage({ | ||
count: 1, // 默认9 | ||
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 | ||
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 | ||
success: function (res) { | ||
cos.postObject({ | ||
Bucket: config.Bucket, Region: config.Region, Key: '1.png', | ||
FilePath: res.tempFilePaths[0], | ||
onProgress: function (info) { | ||
console.log(JSON.stringify(info)); | ||
} | ||
}, requestCallback); | ||
} | ||
}) | ||
}, | ||
}; | ||
|
||
module.exports = dao; |
Oops, something went wrong.