2016-12-19 13 views

答えて

3

が答えを自分で見つけます例https://cloud.google.com/storage/docs/object-basics#storage-upload-object-nodejs

`` `

function uploadFile (bucketName, fileName, callback) { 
    // Instantiates a client 
    const storageClient = Storage(); 

    // References an existing bucket, e.g. "my-bucket" 
    const bucket = storageClient.bucket(bucketName); 

    // Uploads a local file to the bucket, e.g. "./local/path/to/file.txt" 
    bucket.upload(fileName, (err, file) => { 
    if (err) { 
     callback(err); 
     return; 
    } 

    console.log(`File ${file.name} uploaded.`); 
    callback(); 
    }); 
} 

をnodejs次しています。この種のメタデータをオプションに入れる必要があります。どのドキュメントでも見つかりませんでした。

function uploadFile (bucketName, fileName, callback) { 
    // Instantiates a client 
    const storageClient = Storage(); 

    // References an existing bucket, e.g. "my-bucket" 
    const bucket = storageClient.bucket(bucketName); 

    // STARTING FROM HERE 
    const options = { 
    metadata: { 
     contentType: 'image/jpeg', 
    }, 
    } 
    // TO HERE 

    // Uploads a local file to the bucket, e.g. "./local/path/to/file.txt" 
    bucket.upload(fileName, options, (err, file) => { 
    if (err) { 
     callback(err); 
     return; 
    } 

    console.log(`File ${file.name} uploaded.`); 
    callback(); 
    }); 
} 
+0

私はそれも見つかりませんでした – speedDeveloper

関連する問題