Direct File Upload in Java
You can directly call the endpoint using the provided Java client.
Upload a file to DFS Object Storage as in the following example.
String content = "To be, or not to be, that is the question:\n" +
"Whether 'tis nobler in the mind to suffer\n" +
"The slings and arrows of outrageous fortune,\n" +
"Or to take Arms against a Sea of troubles,\n" +
"And by opposing end them: to die, to sleep\n" +
"No more; and by a sleep, to say we end\n" +
"The heart-ache, and the thousand natural shocks\n" +
"That Flesh is heir to? 'Tis a consummation\n" +
"Devoutly to be wished. To die, to sleep,\n" +
"To sleep, perchance to Dream; aye, there's the rub,\n" +
"For in that sleep of death, what dreams may come,\n" +
"When we have shuffled off tis mortal coil,\n";
String objectStorageId = os.getId();
byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
String fileId = "shakespeare/hamlet.txt";
ObjectstorageApi objectstorageApi = new ObjectstorageApi(getDataFactoryApiClient());
objectstorageApi.upload(objectStorageId,
new UploadFileList()
.addFilesItem(new UploadFile()
.id(fileId)
.filename("hamlet.txt")
.content(bytes)
.filesize((long) bytes.length)
));
FCS File Upload in Java
For files higher than 10 Mo, you can make an FCS file upload in Java.
-
Check in files on your FCS.
The checkin operation consists in preparing the file upload, and
retrieving the target URL and the upload ticket.
String fileId = "shakespeare/all-hamlet.txt";
objectstorageApi.checkin(objectStorageId,
new ObjectIdentifier()
.id(fileId));
-
Upload files.
You can upload files directly on the FCS, using the url and the ticket of the
previous call.
For more information, see Web Services and Events: Enterprise IP Exchange:
Uploading Enterprise IP Exchange Files in the Developer Assistance.
-
Commit the files.
Validate and commit the files with the upload receipt returned in the previous
step.
objectstorageApi.commit(objectStorageId,
new CommitReceipt()
.receipt(fcsReceipt));
FCS File Upload in HTTPS REST
For files higher than 10 Mo, you can make an FCS file upload using an HTTPS REST
API call sequence.
-
Check in files on your FCS.
The checkin operation consists in preparing the file upload and
retrieving the target URL and upload ticket.
The checkin URL is:
/data-factory-webapp-docker/resources/v1/objectstorage/<Storage
ID>/checkin
Body example:
{
objects:[
{
id : "demo/folder1/folder2/file1.csv",
correlationId: "0"
},
{
id : "demo/folder1/folder2/file2.csv",
correlationId: "1"
}
]
}
Result example:
{
"url":"https://<environment>-dfcs.3dx-staging.3ds.com/fcs/servlet/fcs/checkin",
"ticket":"QEBlbnZlbG9wQEBmY3NrZXlfM2ZlMTg0MWIy…"
}
-
Upload files.
The upload is a POST HTTP query on the url returned by the previous
step checkin.
Note:
This call is not authenticated. The ticket parameter manages the
security.
The POST request body is a multipart form-data built from:
POST <upload url> HTTP/1.1
Accept: */*
Content-Type:multipart/form-data; boundary=<form boundary>
Connection: Keep-Alive
User-Agent: <user agent>
Content-Length: <body length>
--<form boundary>
Content-Disposition: form-data; name="__fcs__jobTicket"
<ticket value>
--<form boundary>
Content-Disposition: form-data; name="__fcs__nohtml"
true
--<form boundary>
Content-Disposition: form-data; name="__fcs__corelation_<file number>"
<correlationId value>
--<form boundary>
Content-Disposition: form-data; name="file_<file number>"; filename="<file name>"
Content-Type: octet/stream
<stream of the file to upload>
--<form boundary>--
| Status |
Description |
<upload url> |
The URL retrieved by the previous checkin call.
|
<ticket value> |
The checkin authentication ticket retrieved by the previous checkin
call.
|
<form boundary> |
Define the boundary in request. For example,
WebKitFormBoundaryRE4R4A25
|
<body length> |
The size of the body length.
|
<file number> |
The current file index for multiupload (0 for the first, 1 for the next
...)
|
<correlationId value |
The file correlation id defined in the previous call. |
<file name> |
The file identifier. For example,
demo/folder1/folder2/filekey
|
<stream of the file to upload> |
The file content.
|
Upload example:
POST https://euw1-devprol25-dfcs.3dx-staging.3ds.com/fcs/servlet/fcs/checkin
Accept: */*
Content-Type:multipart/form-data; boundary=WebKitFormBoundaryGOhlA5D8yOer0ib5
Connection: Keep-Alive
User-Agent: AZBmY3NrZXlf8
Content-Length: 2346
--WebKitFormBoundaryGOhlA5D8yOer0ib5
Content-Disposition: form-data; name="__fcs__nohtml"
true
--WebKitFormBoundaryGOhlA5D8yOer0ib5
Content-Disposition: form-data; name="__fcs__jobTicket"
QEBlbnZlbG9wQEBmY3NrZXlfM2ZlMTg0MWIy…
--WebKitFormBoundaryGOhlA5D8yOer0ib5
Content-Disposition: form-data; name="__fcs__corelation_0"
0
--WebKitFormBoundaryGOhlA5D8yOer0ib5
Content-Disposition: form-data; name="__fcs__corelation_1"
1
--WebKitFormBoundaryGOhlA5D8yOer0ib5
Content-Disposition: form-data; name="file_0"; filename="file1.csv"
Content-Type: application/octet-stream
(file content)
--WebKitFormBoundaryGOhlA5D8yOer0ib5
Content-Disposition: form-data; name="file_1"; filename="file2.csv"
Content-Type: application/octet-stream
(file content)
--WebKitFormBoundaryGOhlA5D8yOer0ib5--
The result of this query is the receipt, for example:
QEBlbnZlbG9wQEBmY3NrZXlfM2ZiNjk1MWY5N2ExYTUwOEBAdGFyZ2V0QEBmY3Nr...
-
Commit the files.
Validate and commit the files with the upload receipt returned in the previous step,
using this HTTP call:
/data-factory-webapp-docker/resources/v1/objectstorage/<storage ID>/commit
Body example:
{
receipt:"QEBlbnZlbG9wQEBmY3NrZXlfM2ZiNjk1MWY5N2ExYTUwOEBAdGFyZ2V0QEBmY3Nr..."
}
|