> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zixflow.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Upload Attachment

> This API used to upload attachments in zixflow platform. Purpose of API is whenever the user wants to send an attachment in the email. user need to upload attachment in zixflow platform first. zixflow will provide id represents to attachment. and the user can send this id in send email API's attachment field to send attachment along with the email

#### Body

<ParamField body="file" type="file" placeholder="Select Attachment" required>
  The "File" field refers to an attachment file that must be included in an
  email campaign. The file can be in any format, and its size should not exceed
  25 megabytes (MB).
</ParamField>

#### Response

<ResponseField name="status" type="boolean">
  Indicates whether the call was successful. true if successful, false if not.
</ResponseField>

<ResponseField name="message" type="string">
  success or error response message
</ResponseField>

<ResponseField name="data" type="object">
  The contents of uploaded file

  <Expandable title="data">
    <ResponseField name="filename" type="string">
      The name of the file.
    </ResponseField>

    <ResponseField name="size" type="integer">
      The size of the file in bytes.
    </ResponseField>

    <ResponseField name="dateadded" type="string">
      The date and time the file was added.
    </ResponseField>

    <ResponseField name="expirationdate" type="string">
      The expiration date of the file (if specified).
    </ResponseField>

    <ResponseField name="fileid" type="string">
      The unique identifier of the file.
    </ResponseField>

    <ResponseField name="contenttype" type="string">
      The content type of the file.
    </ResponseField>

    <ResponseField name="mediumscreenshotpath" type="string">
      The path to the medium-sized screenshot.
    </ResponseField>

    <ResponseField name="thumbnailpath" type="string">
      The path to the thumbnail.
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cUrl theme={null}
  curl --location --request POST 'https://api.zixflow.com/api/v1/campaign/email/upload' \
  --header 'Authorization: Bearer 56616641ee123b80a36b99fedc2bfa4f0d7f63072d97ddb1578c7a5aa970e7edde6618c7f750beb921aee3eebc9cc48899ee992fa4eb95a663d0e0b2eaa35b73f3b2344c' \
  --form 'file=@"<path-to-file>"'
  ```

  ```js Nodejs theme={null}
  var axios = require('axios');
  var FormData = require('form-data');
  var fs = require('fs');
  var data = new FormData();
  data.append('file', fs.createReadStream('/home/sahil/Downloads/welcome-screen.png'));

  var config = {
    method: 'post',
    url: 'https://api.zixflow.com/api/v1/campaign/email/upload',
    headers: { 
      'Authorization': 'Bearer 56616641ee123b80a36b99fedc2bfa4f0d7f63072d97ddb1578c7a5aa970e7edde6618c7f750beb921aee3eebc9cc48899ee992fa4eb95a663d0e0b2eaa35b73f3b2344c', 
      ...data.getHeaders()
    },
    data : data
  };

  axios(config)
  .then(function (response) {
    console.log(JSON.stringify(response.data));
  })
  .catch(function (error) {
    console.log(error);
  });

  ```

  ```py Python theme={null}
  import requests

  url = "https://api.zixflow.com/api/v1/campaign/email/upload"

  payload={}
  files=[
    ('file',('welcome-screen.png',open('/home/sahil/Downloads/welcome-screen.png','rb'),'image/png'))
  ]
  headers = {
    'Authorization': 'Bearer 56616641ee123b80a36b99fedc2bfa4f0d7f63072d97ddb1578c7a5aa970e7edde6618c7f750beb921aee3eebc9cc48899ee992fa4eb95a663d0e0b2eaa35b73f3b2344c'
  }

  response = requests.request("POST", url, headers=headers, data=payload, files=files)

  print(response.text)
  ```

  ```java JAVA theme={null}
  OkHttpClient client = new OkHttpClient().newBuilder()
    .build();
  MediaType mediaType = MediaType.parse("text/plain");
  RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
    .addFormDataPart("file","welcome-screen.png",
      RequestBody.create(MediaType.parse("application/octet-stream"),
      new File("/home/sahil/Downloads/welcome-screen.png")))
    .build();
  Request request = new Request.Builder()
    .url("https://api.zixflow.com/api/v1/campaign/email/upload")
    .method("POST", body)
    .addHeader("Authorization", "Bearer 56616641ee123b80a36b99fedc2bfa4f0d7f63072d97ddb1578c7a5aa970e7edde6618c7f750beb921aee3eebc9cc48899ee992fa4eb95a663d0e0b2eaa35b73f3b2344c")
    .build();
  Response response = client.newCall(request).execute();
  ```

  ```dart DART theme={null}
  var headers = {
    'Authorization': 'Bearer 56616641ee123b80a36b99fedc2bfa4f0d7f63072d97ddb1578c7a5aa970e7edde6618c7f750beb921aee3eebc9cc48899ee992fa4eb95a663d0e0b2eaa35b73f3b2344c'
  };
  var request = http.MultipartRequest('POST', Uri.parse('https://api.zixflow.com/api/v1/campaign/email/upload'));
  request.files.add(await http.MultipartFile.fromPath('file', '/home/sahil/Downloads/welcome-screen.png'));
  request.headers.addAll(headers);

  http.StreamedResponse response = await request.send();

  if (response.statusCode == 200) {
    print(await response.stream.bytesToString());
  }
  else {
    print(response.reasonPhrase);
  }

  ```
</RequestExample>

<ResponseExample>
  ```json 200-Success theme={null}
  {
    "status": true,
    "data": {
      "filename": "file-welcome-screen-1672054415115.png",
      "size": 7343,
      "dateadded": "2022-12-26T11:33:36.2633971Z",
      "expirationdate": null,
      "fileid": "63a98690b0ec6c81460f4f1d",
      "contenttype": "image/png",
      "mediumscreenshotpath": "93b7fbda-4306-4ab7-bb80-e4375750ea76/mediumscreenshots/file-welcome-screen-1672054415115.png",
      "thumbnailpath": "93b7fbda-4306-4ab7-bb80-e4375750ea76/thumbnails/file-welcome-screen-1672054415115.png"
    },
    "message": "Successfully uploaded file"
  }
  ```

  ```json 400-Bad Request theme={null}
  {
    "status": false,
    "message": "file size exceeded"
  }
  ```

  ```json 401-Unauthorised theme={null}
  {
    "status": false,
    "message": "No token provided"
  }
  ```
</ResponseExample>
