目录

Files:create

Function

Creates file content or metadata. Currently, this API is used only for creating folders.

Scenario

By calling the Files.create API, your app can create folders.

Restrictions

Prototype

Protocol

HTTP POST

Direction

Developer server -> HUAWEI Drive server

URL

https://driveapis.cloud.huawei.com.cn/drive/v1/files

Data Format

Request: Content-Type: application/json

Response: Content-Type: application/json

Path Parameters

None.

Query Parameters

Parameter

Mandatory/Optional

Type

Description

fields

Optional

string

Fields in the request, which are in the partial response format. For details, please refer to Overview.

form

Optional

string

Media format.

prettyPrint

Optional

boolean

Indicates whether to return a response in a human-readable format.

quotaId

Optional

string

User identifier, which can contain a maximum of 40 characters. This parameter is used to restrict the maximum number of API calls for a single user.

callback

Optional

string

Callback function used in JSONP requests.

autoRename

Optional

string

Indicates whether to automatically rename the file. If this parameter is set to true of left empty, the file will be automatically renamed. If this parameter is set to false, the file will not be automatically renamed.

Request Parameters

Request Header

Parameter

Mandatory/Optional

Type

Description

Authorization

Mandatory

string

User authorization information, that is, the access token (AT).

x-hw-trace-id

Optional

string

ID used for service tracing.

x-hw-app-id

Optional

string

App ID.

version

Optional

string

SDK version number.

x-hw-terminal

Optional

string

Device model.

x-hw-os

Optional

string

Device operating system.

unionID

Optional

string

User's UnionID.

User-Agent

Optional

string

App version number or app ID.

x-hw-deviceUUID

Optional

string

UUID of the device.

x-hw-deviceUDID

Optional

string

UDID of the device.

x-hw-appPackageName

Optional

string

App package name.

x-hw-network

Optional

string

Network type. The options include WiFi, 2G, 3G, 4G, 5G, and wire.

Request Body

Parameter

Mandatory/Optional

Type

Description

appSettings

Optional

string

Customized app attribute.

contentExtras.thumbnail.content

Optional

string

Thumbnail data encoded with Base64.

contentExtras.thumbnail.mimeType

Optional

string

MIME type of the thumbnail.

writerHasCopyPermission

Optional

boolean

Indicates whether the current user (assuming the writer role) has permission to copy the file.

createdTime

Optional

string

Time when the file is created.

description

Optional

string

Short description of the file.

mimeType

Mandatory

string

File type. For details, please refer to Overview.

editedTime

Optional

string

Last time when the file was modified.

fileName

Mandatory

string

File name.

id

Optional

string

File ID.

originalFilename

Optional

string

Original file name.

parentFolder[]

Optional

string

Parent folder. The value can be root, applicationData, or the ID of a common folder.

properties

Optional

string

Custom file properties that are universally visible.

favorite

Optional

boolean

Indicates whether the file has been favorited.

writersHasSharePermission

Optional

boolean

Indicates whether the current user (assuming the writer role) has permission to share the file.

Request Example

POST https://driveapis.cloud.huawei.com.cn/drive/v1/files?fields=* HTTP/1.1
Accept: application/json
Content-Type: application/json
Cache-Control: no-cache
Authorization: Bearer CF3NTYZSs7MRmxWyj8ssonQQxDgSPAjnDvrf+91NrpN22LdUrMA30A5Kzz0mf55sWao7e7VeLrmjQ0z2OmwPWlt3S00/L1BJppbTFhIgWb74ZBK8CFImUA==

{
  "favorite": "true",
  "fileName": "test1234",
  "description": "folder",
  "mimeType": "application/vnd.huawei-apps.folder" // Only folders can be created currently.
}

Response Parameters

When the status code is 200:

Parameter

Type

Description

category

string

Resource type. The value is always drive#file.

id

string

File ID.

fileName

string

File name.

mimeType

string

File type. For details, please refer to Overview.

description

string

Short description of the file.

favorite

boolean

Indicates whether the file has been favorited.

recycled

boolean

Indicates whether the file has been moved to the recycle bin.

directlyRecycled

boolean

Indicates whether the file has been explicitly moved to the recycle bin.

recyclingUser.category

string

User type. The value is always drive#user.

recyclingUser.displayName

string

Display name of the user.

recyclingUser.profilePhotoLink

string

Link to the user's profile picture, which is not returned by default.

recyclingUser.me

boolean

Indicates whether the user is the requesting user.

recyclingUser.permissionId

string

Permission ID.

recyclingUser.userAccount

string

Account of the user, which is not returned by default.

recycledTime

string

Time when the file is moved to the recycle bin.

parentFolder[]

string

Parent folder.

properties

string

Custom file properties that are universally visible.

appSettings

string

Customized app attribute.

containers[]

string

Spaces that contain the file. The options include drive and applicationData.

version

integer

Version number of the file.

contentDownloadLink

string

Link for downloading the file in a browser.

iconDownloadLink

string

Link to the file's icon.

existThumbnail

boolean

Indicates whether the file has a thumbnail.

thumbnailDownloadLink

string

Link to the file's large thumbnail.

smallThumbnailDownloadLink

string

Link to the file's small thumbnail.

thumbnailVersion

integer

Thumbnail version number.

onLineViewLink

string

Link to view the file online.

createdTime

string

Time when the file is created.

editedTime

string

Last time when the file was modified.

editedByMeTime

string

Last time when the file was modified by the user.

editedByMe

boolean

Indicates whether the file is modified by the user.

sharedWithMeTime

string

Time when the file is shared with the user.

sharer.category

string

User type. The value is always drive#user.

sharer.displayName

string

Display name of the user.

sharer.profilePhotoLink

string

Link to the user's profile picture, which is not returned by default.

sharer.me

boolean

Indicates whether the user is the requesting user.

sharer.permissionId

string

Permission ID.

sharer.userAccount

string

Account of the user, which is not returned by default.

owners.category

string

User type. The value is always drive#user.

owners.displayName

string

Display name of the user.

owners.profilePhotoLink

string

Link to the user's profile picture, which is not returned by default.

owners.me

boolean

Indicates whether the user is the requesting user.

owners.permissionId

string

Permission ID.

owners.userAccount

string

Account of the user, which is not returned by default.

lastEditor.category

string

User type. The value is always drive#user.

lastEditor.displayName

string

Display name of the user.

lastEditor.profilePhotoLink

string

Link to the user's profile picture, which is not returned by default.

lastEditor.me

boolean

Indicates whether the user is the requesting user.

lastEditor.permissionId

string

Permission ID.

lastEditor.userAccount

string

Account of the user, which is not returned by default.

hasShared

boolean

Indicates whether the file is shared.

ownedByMe

boolean

Indicates whether the user owns the file.

capabilities.addChildNodePermission

boolean

Indicates whether the current user has permission to create subfolders or files to a folder.

capabilities.writerHasChangeCopyPermission

boolean

Indicates whether the current user (assuming the writer role) has permission to change or copy the file.

capabilities.commentPermission

boolean

Indicates whether the current user has permission to comment on the file.

capabilities.copyPermission

boolean

Indicates whether the current user has permission to copy the file.

capabilities.deletePermission

boolean

Indicates whether the current user has permission to delete the file.

capabilities.downloadPermission

boolean

Indicates whether the current user has permission to download the file.

capabilities.editPermission

boolean

Indicates whether the current user has permission to edit the file.

capabilities.listChildNodePermission

boolean

Indicates whether the current user has permission to list subfolders or files in a folder.

capabilities.editContentPermission

boolean

Indicates whether the current user has permission to modify the content of the file.

capabilities.readHistoryVersionPermission

boolean

Indicates whether the current user has permission to read the historical versions of the file.

capabilities.removeChildNodePermission

boolean

Indicates whether the current user has permission to remove subfolders from a folder.

capabilities.renameFilePermission

boolean

Indicates whether the current user has permission to rename the file.

capabilities.shareFilePermission

boolean

Indicates whether the current user has permission to share the file.

capabilities.recyclePermission

boolean

Indicates whether the current user has permission to move the file to the recycle bin.

capabilities.unrecyclePermission

boolean

Indicates whether the current user has permission to restore the file from the recycle bin.

viewersHasCopyContentPermission

boolean

Indicates whether the current user has permission to copy the content of the file.

writerHasCopyPermission

boolean

Indicates whether the current user (assuming the writer role) has permission to copy the file.

writersHasSharePermission

boolean

Indicates whether the current user (assuming the writer role) has permission to share the file.

permissions[]

list

List of permissions for the file.

permission.category

string

Permission category. The value is always drive#permission.

permission.id

string

Permission ID.

permission.type

string

Type of the grantee, which can be user or anyone.

permission.role

string

Role granted by the permission. The options include owner, writer, commenter, and reader.

permission.userAccount

string

Account of the user.

permission.displayName

string

Display name of the permission.

permission.expirationTime

string

Time when the permission expires.

permission.deleted

boolean

Indicates whether the permission is deleted.

permission.canDiscoverFile

boolean

Indicates whether the permission allows the file to be searched. It is applicable only to permissions of the anyone type.

permissionIds

list

List of permission IDs for users with access to the file.

originalFilename

string

Original file name.

fullFileSuffix

string

Full file name suffix extracted from the name field. It is the substring that comes immediately after the dot character in the file name.

fileSuffix

string

Last component of fullFileSuffix.

size

integer

File size.

occupiedSpace

integer

Actual storage used by the file.

pictureMetadata.width

integer

Picture width.

pictureMetadata.height

integer

Picture height.

pictureMetadata.location.latitude

number

Latitude stored in the picture.

pictureMetadata.location.longitude

number

Longitude stored in the picture.

pictureMetadata.location.altitude

number

Altitude stored in the picture.

pictureMetadata.exifTime

string

Date and time when the picture is created (EXIF DateTime).

pictureMetadata.cameraMaker

string

Maker of the camera that is used to create the picture.

pictureMetadata.cameraModel

string

Model of the camera that is used to create the picture.

pictureMetadata.exposureTime

number

Length of the exposure, in seconds.

pictureMetadata.aperture

number

Aperture (f-number) used to create the picture.

pictureMetadata.flashUsed

boolean

Indicates whether a flash is used to create the picture.

pictureMetadata.focalLength

number

Focal length used to create the picture, in millimeters.

pictureMetadata.isoSpeed

integer

ISO speed used to create the picture.

pictureMetadata.meteringMode

string

Metering mode used to create the picture.

pictureMetadata.sensor

string

Type of sensor used to create the picture.

pictureMetadata.exposureMode

string

Exposure mode used to create the picture.

pictureMetadata.colorSpace

string

Color space of the picture.

pictureMetadata.whiteBalance

string

White balance mode used to create the picture.

pictureMetadata.exposureBias

number

Exposure bias of the picture (APEX value).

pictureMetadata.maxApertureValue

number

Maximum aperture used to create the picture (APEX value).

pictureMetadata.lens

string

Lens used to create the picture.

videoMetadata.width

integer

Width of the video.

videoMetadata.height

integer

Height of the video.

videoMetadata.durationTime

integer

Duration of the video, in milliseconds.

sha256

string

SHA-256 value for the file.

lastHistoryVersionId

string

ID of the latest version.

contentVersion

string

Content version number.

Response Example

{
    "fileName":"test1234",
    "capabilities":{
        "downloadPermission":true,
        "renameFilePermission":true,
        "commentPermission":true,
        "deletePermission":true,
        "readHistoryVersionPermission":true,
        "recyclePermission":true,
        "addChildNodePermission":true,
        "unrecyclePermission":true,
        "writerHasChangeCopyPermission":true,
        "copyPermission":true,
        "editContentPermission":true,
        "removeChildNodePermission":true,
        "editPermission":true,
        "listChildNodePermission":true,
        "shareFilePermission":true
    },
    "description":"folder",
    "owners":[
        {
            "permissionId":"239046878371512704",
            "displayName":"*******3121@**3.com",
            "me":true,
            "category":"drive#user"
        }
    ],
    "hasShared":false,
    "mimeType":"application/vnd.huawei-apps.folder",
    "ownedByMe":true,
    "version":1592013188000,
    "permissionIds":[
        "239046878371512704"
    ],
    "lastHistoryVersionId":"AhgJxQhqCuoALUzMcl9P43oVTMpyUgrsA",
    "parentFolder":[
        "AgFovWXIAIYANC20H_1Fj3oMLbIf8ACAA"
    ],
    "iconDownloadLink":"https://event-dre.dbankcdn.com/filemanagerpic/201911140913476Sc7.png",
    "recycled":false,
    "directlyRecycled":false,
    "editedTime":"2020-06-13T01:55:25.000Z",
    "permissions":[
        {
            "role":"owner",
            "deleted":false,
            "displayName":"*******3121@**3.com",
            "id":"239046878371512704",
            "category":"drive#permission",
            "type":"user"
        }
    ],
    "thumbnailVersion":0,
    "lastEditor":{
        "permissionId":"239046878371512704",
        "displayName":"*******3121@**3.com",
        "me":true,
        "category":"drive#user"
    },
    "createdTime":"2020-06-13T01:55:25.000Z",
    "existThumbnail":false,
    "containers":[
        "drive"
    ],
    "id":"AhgJxQhqCuoALUzMcl9P43oVTMpyUgrsA",
    "category":"drive#file",
    "favorite":true
}

Common Result Codes

The last four digits in the result code indicate the service error code, which is used to differentiate error scenarios. For details about other service error codes, please refer to Status Codes.

Status Code

Result Code

Response Code

Description

200

NA

-

Success.

400

21004001

LACK_OF_PARAM

Input parameter is missing. Check the parameter list.

400

21004002

PARAM_INVALID

Parameter verification failed. Check the parameter list.

400

21004003

SERVICE_NOT_SUPPORT

The service is not supported.

500

21005002

SERVER_TEMP_ERROR

Internal service error.

500

21055002

OUTER_SERVICE_UNAVAILABLE

External service is unavailable.

403

21004035

INSUFFICIENT_SCOPE

Insufficient scope permission.

403

21004036

INSUFFICIENT_PERMISSION

Insufficient role permission.

500

21005006

SERVER_TEMP_ERROR

The Drive service is abnormal.

403

21074033

AGREEMENT_NOT_SIGNED

The HUAWEI Drive user agreement is not signed. Try again after the agreement is signed.

403

21084031

DATA_MIGRATINT

The security policy is being updated. Please wait until the update is complete.

500

21085006

SERVER_TEMP_ERROR

Server error.

Call Example

    public static void main(String[] args) throws IOException {
        // Set the request URL, file ID, and access token.
        String url = "https://driveapis.cloud.huawei.com.cn/upload/drive/v1/files";
        String fileId = "AACeJVrcK7wAg6Ae3l8Vh4QNoBLeUiuwA";
        String access_token = "CF3pA9N/bBr1lFcpPsK7v1W9gtIScpAxfsR0VDiTsCj8TIZwQG4yGBaTYHTQgxVXoVcYgXw+hAhMTE904csrrkQ6v7+RhRm8C6yIEOnDi3YteB3bvyj40w==";
        // Create a file and upload it.
        JSONObject fileInfo = filesUpdatePatchcontent(url, access_token, fileId);
        System.out.println(fileInfo.toJSONString());
    }

    private static JSONObject filesUpdatePatchcontent(String url, String access_token, String fileId) throws IOException {
        StringBuilder stringBuilder = new StringBuilder("");
        stringBuilder.append("/").append(fileId);
        stringBuilder.append("?").append("fields=*");
        stringBuilder.append("&").append("uploadType=content");
        HttpPatch httpPatch = new HttpPatch(url + stringBuilder);
        httpPatch.setHeader("Authorization","Bearer " + access_token);
        httpPatch.setHeader("Content-Type", "image/jpeg");
        httpPatch.setHeader("Accept", "application/json");
        httpPatch.setHeader("X-Upload-Content-Type", "image/jpeg");
       
        File file = new File("C:\\Users\\z00502234\\Pictures\\Saved Pictures\\0.jpg"); // Change the file path to your local path.
        if(!file.exists()){
            System.out.print("File not exist");
            return null;
        }
        FileBody bin = new FileBody(file, ContentType.create("image/jpeg", Consts.UTF_8));
      
        HttpEntity entity = MultipartEntityBuilder
            .create()
            .setCharset(Charset.forName("utf-8"))
            .addPart("file", bin)
            .build();
        httpPatch.setEntity(entity);
        RequestConfig requestConfig = RequestConfig.custom()
            .setConnectTimeout(50000).setConnectionRequestTimeout(10000)
            .setSocketTimeout(50000).build();
        httpPatch.setConfig(requestConfig);

        CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPatch);

        try {
            HttpEntity responseEntity = response.getEntity();
            String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null;
            JSONObject jsonObject = (JSONObject) JSON.parse(ret);
            EntityUtils.consume(responseEntity);
            return jsonObject;
        }finally {
            response.close();
        }
    }