Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and
// my-objectname are dummy values, please replace them with original values.
var Minio = require('minio')
var s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY'
})
// Remove a partially uploaded object name my-objectname.
s3Client.removeIncompleteUpload('my-bucketname', 'my-objectname', function(e) {
if (e) {
return console.log(e)
}
console.log("Success")
})
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname
// are dummy values, please replace them with original values.
var Minio = require('minio')
var s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY'
})
// Download the object my-objectname at an offset 1024, for a total of 4096 bytes.
var size = 0
s3Client.getPartialObject('my-bucketname', 'my-objectname', 1024, 4096, function(e, dataStream) {
if (e) {
return console.log(e)
}
dataStream.on('data', function(chunk) {
size += chunk.length
})
dataStream.on('end', function() {
console.log("End. Total size = " + size)
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
// dummy values, please replace them with original values.
var Minio = require('minio')
var s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY'
})
s3Client.bucketExists('my-bucketname', function(err, exists) {
if (err) {
return console.log(err)
}
if (exists) {
console.log("Bucket exists.")
}
})
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Note: YOUR-ACCESSKEYID and YOUR-SECRETACCESSKEY are dummy values, please
// replace them with original values.
var Minio = require('minio')
var s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY'
})
s3Client.listBuckets(function(e, buckets) {
if (e) return console.log(e)
console.log('buckets :', buckets)
})
created(){
this.username_auth = localStorage.getItem("user");
this.password_auth = localStorage.getItem("password");
var minio_endpoint = localStorage.getItem("endpoint");
var minio_port = localStorage.getItem("port");
// var minio_useSSL = localStorage.getItem("useSSL");
var minio_accessKey = localStorage.getItem("accessKey");
var minio_secretKey = localStorage.getItem("secretKey");
var Minio = require('minio')
this.minioClient = new Minio.Client({
endPoint: minio_endpoint,
port: parseInt(minio_port),
useSSL: true,
accessKey: minio_accessKey,
secretKey: minio_secretKey
});
this.minioClient.setRequestOptions({rejectUnauthorized: false})
},
methods: {
const { Client } = require('minio')
const client = new Client({
endPoint: 'localhost',
port: 9000,
secure: false,
accessKey: 'access_key',
secretKey: 'secret_key',
})
async function main() {
const bucketName = 'foo'
// 判断存在并创建
try {
await client.bucketExists(bucketName)
} catch (error) {
if (error.code === 'NoSuchBucket') {
await client.makeBucket(bucketName, 'cn-north-1')
}
if (!config.accessKey || !config.secretKey) {
if (await awsInstanceProfileCredentials.ok()) {
const credentials = await awsInstanceProfileCredentials.getCredentials();
if (credentials) {
const {
AccessKeyId: accessKey,
SecretAccessKey: secretKey,
Token: sessionToken,
} = credentials;
return new MinioClient({ ...config, accessKey, secretKey, sessionToken });
}
console.error('unable to get credentials from AWS metadata store.');
}
}
return new MinioClient(config as MinioClientOptions);
}
}
function listBuckets() {
return minioClient.listBucketsAsync()
}
function createBucket(bucket, region = 'us-east-1') {
if (!bucket || bucket.length <= 1) return Promise.reject(new Error('Invalid bucket argument.'))
return listBuckets()
.then(buckets => buckets.find(({name}) => bucket === name))
.then(exists => exists ? {exists: true, name: bucket} : minioClient.makeBucketAsync(bucket, region))
}
if (blockStorage && blockStorage.port) {
blockStorage.port = parseInt(blockStorage.port, null)
minioClient = new Client(blockStorage)
Promise.promisifyAll(minioClient)
}
constructor(s3Config) {
this.minioClient = new Minio.Client(s3Config);
}
const Minio = require('minio');
const Config = require('../../config');
const Logger = require('../../logger');
const Errors = require('../exceptions/errors');
const minio_client = new Minio.Client({
endPoint: Config.minio.host,
port: Config.minio.port,
secure: Config.minio.secure,
accessKey: Config.minio.accessKey,
secretKey: Config.minio.secretKey,
});
async function create_bucket_if_needed(bucket_name) {
try {
await new Promise((resolve, reject) => {
minio_client.makeBucket(bucket_name, 'us-east-1', (err) => {
if (err) {
return reject(err);
}
return resolve(true);
});