Upload Attachment API
Point-to-point support: No integration required
Update Date: 2024-02-28 Optional integration Can be called directly
API Overview
- Used to upload attachments of customer service or penalty events to Ctrip cloud storage. If you need to use an internal or third-party cloud storage, please contact Ctrip for a security review. After the review is approved, we will whitelist your access.
- The platform regularly monitors attachment storage usage. Please note: Do not upload files unrelated to event tickets, otherwise your access will be revoked
Request Address
Address Format: http(s)://{domain}/file/v1/api/upload?channel={channel}&public={public}&oversea={oversea}&filename={filename}
Please confirm the domain with Ctrip product & engineering team before integration
Request Parameters
| Parameter | Type | Required | Description | Example | Note |
|---|---|---|---|---|---|
| Content-Length | String | Y | Request header parameter, actual file size, following HTTP standard protocol specifications | ||
| Crc | String | Y | Request header parameter, CRC checksum, refer to the code example below | ||
| Content-type | String | Y | Request header parameter, Supported file types for penalty events | ||
| channel | String | Y | URL parameter, identifier for upload source | Please contact Ctrip product & engineering team to obtain | |
| public | String | Y | URL parameter, whether the file is accessible via public network. 0 = Ctrip intranet only, 1 = publicly accessible | If the attachment is only for Ctrip customer service use, please pass 0 | |
| oversea | String | Y | URL parameter, the region where the file URL is applicable. 0 = domestic access, 1 = overseas access | For domestic business, pass 0 directly | |
| filename | String | Y | URL parameter, please pass the urlsafebase64 encoded value: urlsafebase64({serviceproviderid}{filename}) | Java users can call Base64.getUrlEncoder().encodeToString(name) method, pass in "测试abc123.pdf", and verify the encoded result is "5rWL6K VYWJjXzEyMy5wZGY=" to confirm the method works; note: filename can only contain [digits, letters, Chinese characters, -, , /], file extension only supports digits and letters |
Response Content
RedReverseResponse
| Parameter | Type | Required | Description | Example | Note |
|---|---|---|---|---|---|
| file_name | String | Y | Ctrip-encoded filename, format: 7/{channel}/{your_custom_filename} | 7/{channel}/1000013_6.pdf | Note: files with the same name cannot be overwritten; a second upload will return a 409 or 400 error |
| url | String | Y | File URL | https://ws.downloadfile.fx.ctripcorp.com/files/7/{channel}/1000013_6.pdf |
Please determine the request result based on the HTTP response code:
200 (OK)
400 (Parameter error)
401 (Valid token required or expired)
409 (Filename already exists)
411 (Content-Length required)
412 (CRC checksum incorrect)
413 (File size cannot exceed 50M)
415 (Unsupported image format)
416 (Unsupported file format)
500 (Exception)
CRC Checksum
public static String getCrc(byte[] fileBytes) throws NoSuchAlgorithmException {
byte[] tmp;
int size5M = 5 * 1024 * 1024;
int size10M = 10 * 1024 * 1024;
if (fileBytes.length > size10M) {
tmp = new byte[size10M];
System.arraycopy(fileBytes, 0, tmp, 0, size5M);
System.arraycopy(fileBytes, fileBytes.length - size5M, tmp, size5M, size5M); }
else {
tmp = fileBytes;
}
MessageDigest m=MessageDigest.getInstance("MD5");
byte[] digest = m.digest(tmp);
return Hex.encodeHexString(digest);
}
Request Example
Filename: 1000013_6.pdf
Request URL: http://file.c-ctrip.com/file/v1/api/upload?channel={channel}&public=0&oversea=0&filename=MTAwMDAxM182LnBkZg==
base64: MTAwMDAxM182LnBkZg==
crc: aec1af77b93c5158282f844b83c23556
Response Example
{
"file_name":"7/{channel}/1000013_6.pdf",
"url":"https://ws.downloadfile.fx.ctripcorp.com/files/7/{channel}/1000013_6.pdf"
}