@@ -116,7 +116,7 @@ https://myaccount.file.core.windows.net/myshare/mydirectorypath/myfile
116116### Handling Exceptions
117117Uses the ` shareServiceClient ` generated from [ shareSeviceClient] ( #share-service ) section below.
118118
119- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L223-L227 -->
119+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L224-L228 -->
120120``` java
121121try {
122122 shareServiceClient. createShare(" myShare" );
@@ -160,7 +160,7 @@ Note that metadata names preserve the case with which they were created, but are
160160The File Share Service REST API provides operations on accounts and manage file service properties. It allows the operations of listing and deleting shares, getting and setting file service properties.
161161Once you have the SASToken, you can construct the ` shareServiceClient ` with ` ${accountName} ` , ` ${sasToken} `
162162
163- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L53-L55 -->
163+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L54-L56 -->
164164``` java
165165String shareServiceURL = String . format(" https://%s.file.core.windows.net" , ACCOUNT_NAME );
166166ShareServiceClient shareServiceClient = new ShareServiceClientBuilder (). endpoint(shareServiceURL)
@@ -171,7 +171,7 @@ ShareServiceClient shareServiceClient = new ShareServiceClientBuilder().endpoint
171171The share resource includes metadata and properties for that share. It allows the opertions of creating, creating snapshot, deleting shares, getting share properties, setting metadata, getting and setting ACL (Access policy).
172172Once you have the SASToken, you can construct the file service client with ` ${accountName} ` , ` ${shareName} ` , ` ${sasToken} `
173173
174- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L60-L62 -->
174+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L61-L63 -->
175175``` java
176176String shareURL = String . format(" https://%s.file.core.windows.net" , ACCOUNT_NAME );
177177ShareClient shareClient = new ShareClientBuilder (). endpoint(shareURL)
@@ -182,7 +182,7 @@ ShareClient shareClient = new ShareClientBuilder().endpoint(shareURL)
182182 The directory resource includes the properties for that directory. It allows the operations of creating, listing, deleting directories or subdirectories or files, getting properties, setting metadata, listing and force closing the handles.
183183 Once you have the SASToken, you can construct the file service client with ` ${accountName} ` , ` ${shareName} ` , ` ${directoryPath} ` , ` ${sasToken} `
184184
185- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L68-L70 -->
185+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L69-L71 -->
186186``` java
187187String directoryURL = String . format(" https://%s.file.core.windows.net" , ACCOUNT_NAME );
188188ShareDirectoryClient directoryClient = new ShareFileClientBuilder (). endpoint(directoryURL)
@@ -193,7 +193,7 @@ ShareDirectoryClient directoryClient = new ShareFileClientBuilder().endpoint(dir
193193 The file resource includes the properties for that file. It allows the operations of creating, uploading, copying, downloading, deleting files or range of the files, getting properties, setting metadata, listing and force closing the handles.
194194 Once you have the SASToken, you can construct the file service client with ` ${accountName} ` , ` ${shareName} ` , ` ${directoryPath} ` , ` ${fileName} ` , ` ${sasToken} `
195195
196- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L77-L79 -->
196+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L78-L80 -->
197197``` java
198198String fileURL = String . format(" https://%s.file.core.windows.net" , ACCOUNT_NAME );
199199ShareFileClient fileClient = new ShareFileClientBuilder (). connectionString(CONNECTION_STRING )
@@ -218,6 +218,7 @@ The following sections provide several code snippets covering some of the most c
218218- [ Copy a File] ( #copy-a-file )
219219- [ Abort copy a File] ( #abort-copy-a-file )
220220- [ Upload data to Storage File] ( #upload-data-to-storage )
221+ - [ Upload data bigger than 4 MB to Storage File] ( #upload-data-bigger-than-4-mb-to-storage )
221222- [ Upload file to Storage File] ( #upload-file-to-storage )
222223- [ Download data from file range] ( #download-data-from-file-range )
223224- [ Download file from Storage File] ( #download-file-from-storage )
@@ -235,7 +236,7 @@ The following sections provide several code snippets covering some of the most c
235236Create a share in the Storage Account. Throws StorageException If the share fails to be created.
236237Taking a ShareServiceClient in KeyConcept, [ ` ${shareServiceClient} ` ] ( #share-services ) .
237238
238- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L83- L84 -->
239+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L84-L85 -->
239240``` Java
240241String shareName = " testshare" ;
241242shareServiceClient. createShare(shareName);
@@ -244,7 +245,7 @@ shareServiceClient.createShare(shareName);
244245### Create a snapshot on Share
245246Taking a ShareServiceClient in KeyConcept, [ ` ${shareServiceClient} ` ] ( #share-services ) .
246247
247- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L88-L90 -->
248+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L89-L91 -->
248249``` Java
249250String shareName = " testshare" ;
250251ShareClient shareClient = shareServiceClient. getShareClient(shareName);
@@ -254,7 +255,7 @@ shareClient.createSnapshot();
254255### Create a directory
255256Taking the [ ` ${shareClient} ` ] ( #create-a-snapshot-on-share ) initialized above, [ ` ${shareClient} ` ] ( #share ) .
256257
257- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L94- L95 -->
258+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L95-L96 -->
258259``` Java
259260String dirName = " testdir" ;
260261shareClient. createDirectory(dirName);
@@ -263,7 +264,7 @@ shareClient.createDirectory(dirName);
263264### Create a subdirectory
264265Taking the directoryClient in KeyConcept, [ ` ${directoryClient} ` ] ( #directory ) .
265266
266- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L99- L100 -->
267+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L100-L101 -->
267268``` Java
268269String subDirName = " testsubdir" ;
269270directoryClient. createSubdirectory(subDirName);
@@ -272,7 +273,7 @@ directoryClient.createSubdirectory(subDirName);
272273### Create a File
273274Taking the directoryClient in KeyConcept, [ ` ${directoryClient} ` ] ( #directory ) .
274275
275- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L104-L106 -->
276+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L105-L107 -->
276277``` Java
277278String fileName = " testfile" ;
278279long maxSize = 1024 ;
@@ -282,39 +283,39 @@ directoryClient.createFile(fileName, maxSize);
282283### List all Shares
283284Taking the shareServiceClient in KeyConcept, [ ` ${shareServiceClient} ` ] ( #share-services )
284285
285- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L110-L110 -->
286+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L111-L111 -->
286287``` Java
287288shareServiceClient. listShares();
288289```
289290
290291### List all subdirectories and files
291292Taking the directoryClient in KeyConcept, [ ` ${directoryClient} ` ] ( #directory )
292293
293- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L114-L114 -->
294+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L115-L115 -->
294295``` Java
295296directoryClient. listFilesAndDirectories();
296297```
297298
298299### List all ranges on file
299300Taking the fileClient in KeyConcept, [ ` ${fileClient} ` ] ( #file )
300301
301- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L118-L118 -->
302+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L119-L119 -->
302303``` Java
303304fileClient. listRanges();
304305```
305306
306307### Delete a share
307308Taking the shareClient in KeyConcept, [ ` ${shareClient} ` ] ( #share )
308309
309- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L122-L122 -->
310+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L123-L123 -->
310311``` Java
311312shareClient. delete();
312313```
313314
314315### Delete a directory
315316Taking the shareClient in KeyConcept, [ ` ${shareClient} ` ] ( #share ) .
316317
317- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L126- L127 -->
318+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L127-L128 -->
318319``` Java
319320String dirName = " testdir" ;
320321shareClient. deleteDirectory(dirName);
@@ -323,7 +324,7 @@ shareClient.deleteDirectory(dirName);
323324### Delete a subdirectory
324325Taking the directoryClient in KeyConcept, [ ` ${directoryClient} ` ] ( #directory ) .
325326
326- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L131- L132 -->
327+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L132-L133 -->
327328``` Java
328329String subDirName = " testsubdir" ;
329330directoryClient. deleteSubdirectory(subDirName);
@@ -332,7 +333,7 @@ directoryClient.deleteSubdirectory(subDirName);
332333### Delete a file
333334Taking the directoryClient in KeyConcept, [ ` ${directoryClient} ` ] ( #directory ) .
334335
335- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L136- L137 -->
336+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L137-L138 -->
336337``` Java
337338String fileName = " testfile" ;
338339directoryClient. deleteFile(fileName);
@@ -341,7 +342,7 @@ directoryClient.deleteFile(fileName);
341342### Copy a file
342343Taking the fileClient in KeyConcept, [ ` ${fileClient} ` ] ( #file ) with string of source URL.
343344
344- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L141-L143 -->
345+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L142-L144 -->
345346``` Java
346347String sourceURL = " https://myaccount.file.core.windows.net/myshare/myfile" ;
347348Duration pollInterval = Duration . ofSeconds(2 );
@@ -351,25 +352,57 @@ SyncPoller<ShareFileCopyInfo, Void> poller = fileClient.beginCopy(sourceURL, nul
351352### Abort copy a file
352353Taking the fileClient in KeyConcept, [ ` ${fileClient} ` ] ( #file ) with the copy info response returned above ` ${copyId}=[copyInfoResponse](#copy-a-file) ` .
353354
354- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L147-L147 -->
355+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L148-L148 -->
355356``` Java
356357fileClient. abortCopy(" copyId" );
357358```
358359
359360### Upload data to storage
360361Taking the fileClient in KeyConcept, [ ` ${fileClient} ` ] ( #file ) with data of "default" .
361362
362- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L151-L153 -->
363+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L152-L154 -->
363364``` Java
364365String uploadText = " default" ;
365366InputStream data = new ByteArrayInputStream (uploadText. getBytes(StandardCharsets . UTF_8 ));
366367fileClient. upload(data, uploadText. length());
367368```
368369
370+ ### Upload data bigger than 4 MB to storage
371+ Taking the fileClient in KeyConcept, [ ` ${fileClient} ` ] ( #file ) with data of "default" .
372+
373+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L232-L256 -->
374+ ``` Java
375+ byte [] data = " Hello, data sample!" . getBytes(StandardCharsets . UTF_8 );
376+
377+ long chunkSize = ShareFileAsyncClient . FILE_DEFAULT_BLOCK_SIZE ;
378+ if (data. length > chunkSize) {
379+ for (int offset = 0 ; offset < data. length; offset += chunkSize) {
380+ try {
381+ // the last chunk size is smaller than the others
382+ chunkSize = Math . min(data. length - offset, chunkSize);
383+
384+ // select the chunk in the byte array
385+ byte [] subArray = Arrays . copyOfRange(data, offset, (int ) (offset + chunkSize));
386+
387+ // upload the chunk
388+ fileClient. uploadWithResponse(new ByteArrayInputStream (subArray), chunkSize, (long ) offset, null , Context . NONE );
389+ } catch (RuntimeException e) {
390+ logger. error(" Failed to upload the file" , e);
391+ if (Boolean . TRUE. equals(fileClient. exists())) {
392+ fileClient. delete();
393+ }
394+ throw e;
395+ }
396+ }
397+ } else {
398+ fileClient. upload(new ByteArrayInputStream (data), data. length);
399+ }
400+ ```
401+
369402### Upload file to storage
370403Taking the fileClient in KeyConcept, [ ` ${fileClient} ` ] ( #file ) .
371404
372- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L157- L158 -->
405+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L158-L159 -->
373406``` Java
374407String filePath = " ${myLocalFilePath}" ;
375408fileClient. uploadFromFile(filePath);
@@ -378,7 +411,7 @@ fileClient.uploadFromFile(filePath);
378411### Download data from file range
379412Taking the fileClient in KeyConcept, [ ` ${fileClient} ` ] ( #file ) with the range from 1024 to 2048.
380413
381- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L162-L164 -->
414+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L163-L165 -->
382415``` Java
383416ShareFileRange fileRange = new ShareFileRange (0L , 2048L );
384417OutputStream stream = new ByteArrayOutputStream ();
@@ -388,7 +421,7 @@ fileClient.downloadWithResponse(stream, fileRange, false, null, Context.NONE);
388421### Download file from storage
389422Taking the fileClient in KeyConcept, [ ` ${fileClient} ` ] ( #file ) and download to the file of filePath.
390423
391- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L168- L169 -->
424+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L169-L170 -->
392425``` Java
393426String filePath = " ${myLocalFilePath}" ;
394427fileClient. downloadToFile(filePath);
@@ -397,15 +430,15 @@ fileClient.downloadToFile(filePath);
397430### Get a share service properties
398431Taking a ShareServiceClient in KeyConcept, [ ` ${shareServiceClient} ` ] ( #share-services ) .
399432
400- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L173-L173 -->
433+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L174-L174 -->
401434``` Java
402435shareServiceClient. getProperties();
403436```
404437
405438### Set a share service properties
406439Taking a ShareServiceClient in KeyConcept, [ ` ${shareServiceClient} ` ] ( #share-services ) .
407440
408- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L177-L182 -->
441+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L178-L183 -->
409442``` Java
410443ShareServiceProperties properties = shareServiceClient. getProperties();
411444
@@ -418,7 +451,7 @@ shareServiceClient.setProperties(properties);
418451### Set a share metadata
419452Taking the shareClient in KeyConcept, [ ` ${shareClient} ` ] ( #share ) .
420453
421- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L186- L187 -->
454+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L187-L188 -->
422455``` Java
423456Map<String , String > metadata = Collections . singletonMap(" directory" , " metadata" );
424457shareClient. setMetadata(metadata);
@@ -427,15 +460,15 @@ shareClient.setMetadata(metadata);
427460### Get a share access policy
428461Taking the shareClient in KeyConcept, [ ` ${shareClient} ` ] ( #share )
429462
430- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L191-L191 -->
463+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L192-L192 -->
431464``` Java
432465shareClient. getAccessPolicy();
433466```
434467
435468### Set a share access policy
436469Taking the shareClient in KeyConcept, [ ` ${shareClient} ` ] ( #share ) .
437470
438- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L195-L199 -->
471+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L196-L200 -->
439472``` java
440473ShareAccessPolicy accessPolicy = new ShareAccessPolicy (). setPermissions(" r" )
441474 .setStartsOn(OffsetDateTime . now(ZoneOffset . UTC ))
@@ -447,15 +480,15 @@ shareClient.setAccessPolicy(Collections.singletonList(permission));
447480### Get handles on directory file
448481Taking the directoryClient in KeyConcept, [ ` ${directoryClient} ` ] ( #directory )
449482
450- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L203-L203 -->
483+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L204-L204 -->
451484``` Java
452485PagedIterable<HandleItem > handleItems = directoryClient. listHandles(null , true , Duration . ofSeconds(30 ), Context . NONE );
453486```
454487
455488### Force close handles on handle id
456489Taking the directoryClient in KeyConcept, [ ` ${directoryClient} ` ] ( #directory ) and the handle id returned above ` ${handleId}=[handleItems](#get-handles-on-directory-file) `
457490
458- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L208- L209 -->
491+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L209-L210 -->
459492``` Java
460493String handleId = handleItems. iterator(). next(). getHandleId();
461494directoryClient. forceCloseHandleWithResponse(handleId, Duration . ofSeconds(30 ), Context . NONE );
@@ -464,7 +497,7 @@ directoryClient.forceCloseHandleWithResponse(handleId, Duration.ofSeconds(30), C
464497### Set quota on share
465498Taking the shareClient in KeyConcept, [ ` ${shareClient} ` ] ( #share ) .
466499
467- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L213- L214 -->
500+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L214-L215 -->
468501``` Java
469502int quotaOnGB = 1 ;
470503shareClient. setPropertiesWithResponse(new ShareSetPropertiesOptions (). setQuotaInGb(quotaOnGB), null , Context . NONE );
@@ -473,7 +506,7 @@ shareClient.setPropertiesWithResponse(new ShareSetPropertiesOptions().setQuotaIn
473506### Set file httpheaders
474507Taking the fileClient in KeyConcept, [ ` ${fileClient} ` ] ( #file ) .
475508
476- <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L218- L219 -->
509+ <!-- embedme ./src/samples/java/com/azure/storage/file/share/ReadmeSamples.java#L219-L220 -->
477510``` Java
478511ShareFileHttpHeaders httpHeaders = new ShareFileHttpHeaders (). setContentType(" text/plain" );
479512fileClient. setProperties(1024 , httpHeaders, null , null );
0 commit comments