﻿---
sidebar_position: 3
description: Init parts upload and other functions to work with S3 in the Open Integration Package, a free open-source integration library for 1C:Enterprise 8, OneScript and CLI
keywords: [1C, 1С, 1С:Enterprise, 1С:Enterprise 8.3, API, Integration, Services, Exchange, OneScript, CLI, S3]
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Init parts upload
 Initializes the multipart object uploading



`Function InitPartsUpload(Val Name, Val Bucket, Val BasicData, Val Headers = Undefined) Export`

  | Parameter | CLI option | Type | Required | Description |
  |-|-|-|-|-|
  | Name | --name | String | &#x2714; | Name of the object in the bucket |
  | Bucket | --bucket | String | &#x2714; | Name of the bucket to put the object |
  | BasicData | --basic | Structure Of KeyAndValue | &#x2714; | Basic request data. See GetBasicDataStructure |
  | Headers | --headers | Map Of KeyAndValue | &#x2716; | Additional request headers, if necessary |

  
  Returns:  Structure Of KeyAndValue - serialized JSON response from storage

<br/>

:::tip
Method at AWS documentation: [CreateMultipartUpload](https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html)

This is a service method. A `PutObject` method is intended for the common scenario of files uploading<br/>Using multipart upload for files &lt; 5 MB or when the size of a single chunk is &lt; 5 MB will result in an error
:::
<br/>



```bsl title="1C:Enterprise/OneScript code example"
    URL       = "storage-155.s3hoster.by";
    AccessKey = "BRN5RKJE67...";
    SecretKey = "NNhv+i9PrytpT8Tu0C1N...";
    Region    = "BTC";

    BasicData = OPI_S3.GetBasicDataStructure(URL, AccessKey, SecretKey, Region);

    Name   = "fileChunked.mp3";
    Bucket = "opi-gpbucket3";

    Entity = "https://api.athenaeum.digital/test_data/song.mp3"; // URL, Path or Binary Data
    Entity = OPI_HTTPRequests.Get(Entity);

    Result = OPI_S3.InitPartsUpload(Name, Bucket, BasicData);
    // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    UploadID   = Result["response"]["InitiateMultipartUploadResult"]["UploadId"];
    TotalSize  = Entity.Size();
    ChunkSize  = 5242880;
    BytesRead  = 0;
    PartNumber = 1;

    DataReader   = New DataReader(Entity);
    SourceStream = DataReader.SourceStream();
    TagsArray    = New Array;

    While BytesRead < TotalSize Do

        CurrentReading = DataReader.Read(ChunkSize);
        CurrentData    = CurrentReading.GetBinaryData();

        If CurrentData.Size() = 0 Then
            Break;
        EndIf;

        Result = OPI_S3.UploadObjectPart(Name, Bucket, BasicData, UploadID, PartNumber,
            CurrentData);

        BytesRead = SourceStream.CurrentPosition();

        ETag = Result["headers"]["Etag"];
        ETag = ?(ETag = Undefined, Result["headers"]["ETag"], ETag);

        TagsArray.Add(ETag);

        PartNumber = PartNumber + 1;

    EndDo;

    Result = OPI_S3.FinishPartsUpload(Name, Bucket, BasicData, UploadID, TagsArray);
```
 

 <Tabs>
  
    <TabItem value="bash" label="Bash" default>
        ```bash
            # JSON data can also be passed as a path to a .json file
            
            oint s3 InitPartsUpload \
             --name "fileChunked.mp3" \
             --bucket "opi-gpbucket3" \
             --basic "{'URL':'storage-155.s3hoster.by','AccessKey':'***','SecretKey':'***','Region':'BTC','Service':'s3'}"
        ```
    </TabItem>
  
    <TabItem value="bat" label="CMD/Bat" default>
        ```batch
            :: JSON data can also be passed as a path to a .json file
            
            oint s3 InitPartsUpload ^
             --name "fileChunked.mp3" ^
             --bucket "opi-gpbucket3" ^
             --basic "{'URL':'storage-155.s3hoster.by','AccessKey':'***','SecretKey':'***','Region':'BTC','Service':'s3'}"
        ```
    </TabItem>
</Tabs>


```json title="Result"
{
 "status": 200,
 "response": {
  "InitiateMultipartUploadResult": {
   "Bucket": "opi-gpbucket3",
   "Key": "fileChunked.mp3",
   "UploadId": "MDk2NGE5MDUtNDcxZS00ZDljLTkzYjMtODM5ZDM4NGMyMWVhLjAyMTdkMzc2LWExZGItNGQzZC1iZTZlLWI5MTk3NDQxYmM4MA"
  }
 },
 "headers": {
  "Accept-Ranges": "bytes",
  "Content-Length": "325",
  "Content-Type": "application/xml",
  "Date": "Fri, 22 Nov 2024 10:12:14 GMT",
  "Server": "MinIO",
  "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
  "Vary": "Origin,Accept-Encoding",
  "X-Amz-Id-2": "0757065d17b69556603743b9ea63f04bc7b9f349245bbff6b0ba901258e9c169",
  "X-Amz-Request-Id": "180A42B102AC0011",
  "X-Content-Type-Options": "nosniff",
  "X-Xss-Protection": "1; mode=block"
 }
}
```
