Skip to content

Commit 589e294

Browse files
committed
edits
1 parent ffa3de6 commit 589e294

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

articles/storage/blobs/storage-blob-upload-javascript.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,71 @@ Transform the stream during the upload for data clean up.
4949

5050
:::code language="javascript" source="~/azure_storage-snippets/blobs/howto/JavaScript/NodeJS-v12/dev-guide/upload-blob-from-stream.js" id="Snippet_Transform" :::
5151

52+
The following code demonstrates how to use the function.
53+
54+
```javascript
55+
// fully qualified path to file
56+
const localFileWithPath = path.join(__dirname, `my-text-file.txt`);
57+
58+
// encoding: just to see the chunk as it goes by in the transform
59+
const streamOptions = { highWaterMark: 20, encoding: 'utf-8' }
60+
61+
const readableStream = fs.createReadStream(localFileWithPath, streamOptions);
62+
63+
// upload options
64+
const uploadOptions = {
65+
66+
// not indexed for searching
67+
metadata: {
68+
owner: 'PhillyProject'
69+
},
70+
71+
// indexed for searching
72+
tags: {
73+
createdBy: 'YOUR-NAME',
74+
createdWith: `StorageSnippetsForDocs-${i}`,
75+
createdOn: (new Date()).toDateString()
76+
}
77+
}
78+
79+
// upload stream
80+
await createBlobFromReadStream(containerClient, `my-text-file.txt`, readableStream, uploadOptions);
81+
```
82+
5283
## <a name="upload-by-using-a-binarydata-object"></a>Upload with BlockBlobClient by using a BinaryData object
5384

5485
The following example uploads a Node.js buffer to blob storage with the [BlockBlobClient](/javascript/api/@azure/storage-blob/blockblobclient) object. Pass in the BlockBlobParallelUpload [options](/javascript/api/@azure/storage-blob/blockblobparalleluploadoptions) to affect the upload:
5586

5687
:::code language="javascript" source="~/azure_storage-snippets/blobs/howto/JavaScript/NodeJS-v12/dev-guide/upload-blob-from-buffer.js" id="Snippet_UploadBlob" highlight="17":::
5788

89+
The following code demonstrates how to use the function.
90+
91+
```javascript
92+
// fully qualified path to file
93+
const localFileWithPath = path.join(__dirname, `daisies.jpg`);
94+
95+
// read file into buffer
96+
const buffer = await fs.readFile(localFileWithPath);
97+
98+
// upload options
99+
const uploadOptions = {
100+
101+
// not indexed for searching
102+
metadata: {
103+
owner: 'PhillyProject'
104+
},
105+
106+
// indexed for searching
107+
tags: {
108+
createdBy: 'YOUR-NAME',
109+
createdWith: `StorageSnippetsForDocs-${i}`,
110+
createdOn: (new Date()).toDateString()
111+
}
112+
}
113+
114+
// upload buffer
115+
createBlobFromBuffer(containerClient, `daisies.jpg`, buffer, uploadOptions)
116+
```
58117

59118
## <a name="upload-a-string"></a>Upload a string with BlockBlobClient
60119

0 commit comments

Comments
 (0)