java/resources/uploads/methods/create/index.md +0 −231 deleted
File Deleted View Diff
1## Create upload
2
3`Upload uploads().create(UploadCreateParamsparams, RequestOptionsrequestOptions = RequestOptions.none())`
4
5**post** `/uploads`
6
7Creates an intermediate [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object
8that you can add [Parts](https://platform.openai.com/docs/api-reference/uploads/part-object) to.
9Currently, an Upload can accept at most 8 GB in total and expires after an
10hour after you create it.
11
12Once you complete the Upload, we will create a
13[File](https://platform.openai.com/docs/api-reference/files/object) object that contains all the parts
14you uploaded. This File is usable in the rest of our platform as a regular
15File object.
16
17For certain `purpose` values, the correct `mime_type` must be specified.
18Please refer to documentation for the
19[supported MIME types for your use case](https://platform.openai.com/docs/assistants/tools/file-search#supported-files).
20
21For guidance on the proper filename extensions for each purpose, please
22follow the documentation on [creating a
23File](https://platform.openai.com/docs/api-reference/files/create).
24
25Returns the Upload object with status `pending`.
26
27### Parameters
28
29- `UploadCreateParams params`
30
31 - `long bytes`
32
33 The number of bytes in the file you are uploading.
34
35 - `String filename`
36
37 The name of the file to upload.
38
39 - `String mimeType`
40
41 The MIME type of the file.
42
43 This must fall within the supported MIME types for your file purpose. See
44 the supported MIME types for assistants and vision.
45
46 - `FilePurpose purpose`
47
48 The intended purpose of the uploaded file.
49
50 See the [documentation on File
51 purposes](https://platform.openai.com/docs/api-reference/files/create#files-create-purpose).
52
53 - `Optional<ExpiresAfter> expiresAfter`
54
55 The expiration policy for a file. By default, files with `purpose=batch` expire after 30 days and all other files are persisted until they are manually deleted.
56
57 - `JsonValue; anchor "created_at"constant`
58
59 Anchor timestamp after which the expiration policy applies. Supported anchors: `created_at`.
60
61 - `CREATED_AT("created_at")`
62
63 - `long seconds`
64
65 The number of seconds after the anchor time that the file will expire. Must be between 3600 (1 hour) and 2592000 (30 days).
66
67### Returns
68
69- `class Upload:`
70
71 The Upload object can accept byte chunks in the form of Parts.
72
73 - `String id`
74
75 The Upload unique identifier, which can be referenced in API endpoints.
76
77 - `long bytes`
78
79 The intended number of bytes to be uploaded.
80
81 - `long createdAt`
82
83 The Unix timestamp (in seconds) for when the Upload was created.
84
85 - `long expiresAt`
86
87 The Unix timestamp (in seconds) for when the Upload will expire.
88
89 - `String filename`
90
91 The name of the file to be uploaded.
92
93 - `JsonValue; object_ "upload"constant`
94
95 The object type, which is always "upload".
96
97 - `UPLOAD("upload")`
98
99 - `String purpose`
100
101 The intended purpose of the file. [Please refer here](https://platform.openai.com/docs/api-reference/files/object#files/object-purpose) for acceptable values.
102
103 - `Status status`
104
105 The status of the Upload.
106
107 - `PENDING("pending")`
108
109 - `COMPLETED("completed")`
110
111 - `CANCELLED("cancelled")`
112
113 - `EXPIRED("expired")`
114
115 - `Optional<FileObject> file`
116
117 The `File` object represents a document that has been uploaded to OpenAI.
118
119 - `String id`
120
121 The file identifier, which can be referenced in the API endpoints.
122
123 - `long bytes`
124
125 The size of the file, in bytes.
126
127 - `long createdAt`
128
129 The Unix timestamp (in seconds) for when the file was created.
130
131 - `String filename`
132
133 The name of the file.
134
135 - `JsonValue; object_ "file"constant`
136
137 The object type, which is always `file`.
138
139 - `FILE("file")`
140
141 - `Purpose purpose`
142
143 The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`, `vision`, and `user_data`.
144
145 - `ASSISTANTS("assistants")`
146
147 - `ASSISTANTS_OUTPUT("assistants_output")`
148
149 - `BATCH("batch")`
150
151 - `BATCH_OUTPUT("batch_output")`
152
153 - `FINE_TUNE("fine-tune")`
154
155 - `FINE_TUNE_RESULTS("fine-tune-results")`
156
157 - `VISION("vision")`
158
159 - `USER_DATA("user_data")`
160
161 - `Status status`
162
163 Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.
164
165 - `UPLOADED("uploaded")`
166
167 - `PROCESSED("processed")`
168
169 - `ERROR("error")`
170
171 - `Optional<Long> expiresAt`
172
173 The Unix timestamp (in seconds) for when the file will expire.
174
175 - `Optional<String> statusDetails`
176
177 Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.
178
179### Example
180
181```java
182package com.openai.example;
183
184import com.openai.client.OpenAIClient;
185import com.openai.client.okhttp.OpenAIOkHttpClient;
186import com.openai.models.files.FilePurpose;
187import com.openai.models.uploads.Upload;
188import com.openai.models.uploads.UploadCreateParams;
189
190public final class Main {
191 private Main() {}
192
193 public static void main(String[] args) {
194 OpenAIClient client = OpenAIOkHttpClient.fromEnv();
195
196 UploadCreateParams params = UploadCreateParams.builder()
197 .bytes(0L)
198 .filename("filename")
199 .mimeType("mime_type")
200 .purpose(FilePurpose.ASSISTANTS)
201 .build();
202 Upload upload = client.uploads().create(params);
203 }
204}
205```
206
207#### Response
208
209```json
210{
211 "id": "id",
212 "bytes": 0,
213 "created_at": 0,
214 "expires_at": 0,
215 "filename": "filename",
216 "object": "upload",
217 "purpose": "purpose",
218 "status": "pending",
219 "file": {
220 "id": "id",
221 "bytes": 0,
222 "created_at": 0,
223 "filename": "filename",
224 "object": "file",
225 "purpose": "assistants",
226 "status": "uploaded",
227 "expires_at": 0,
228 "status_details": "status_details"
229 }
230}
231```