Uploading Files and Associating Work Items
Function
This API is used to upload an attachment to a work item in an IPD project. You can use the project ID and work item ID to associate a work item with a file.
Calling Method
For details, see Calling APIs.
URI
POST /v1/ipdprojectservice/projects/{project_id}/issues/{issue_id}/attachments/upload
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| project_id | Yes | String | Definition: 32-character ID of a project, which must be unique. Obtain the value by calling the Querying the IPD Project List API. The value of id in the response message body is the project ID. Constraints: N/A Value range: N/A Default value: N/A |
| issue_id | Yes | String | Definition: Unique ID of a work item. You can obtain the value from the Querying Work Items or Querying Tree-shaped Work Items API. The value is id in the response body. Constraints: N/A Value range: N/A Default value: N/A |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| attachment | Yes | File | Definition: Attachment. Constraints: N/A Value range: N/A Default value: N/A |
Response Parameters
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| status | String | Definition: Response status. Value range: success: The response is successful. error: The response failed. |
| message | String | Definition: Failure information. Options: N/A |
| result | Array of AttachmentVoExt objects | Definition: Attachment upload information. |
| Parameter | Type | Description |
|---|---|---|
| progress | Integer | Definition: Upload progress. Options: N/A |
| id | String | Definition: Attachment ID. Value range: N/A |
| workitem_id | String | Definition: Work item ID. Value range: N/A |
| store_filename | String | Definition: File name. Value range: N/A |
| associate_type | String | Definition: Association type. Value range: N/A |
| disk_directory | String | Definition: Relative path for storing attachments on the server. Value range: N/A |
| type | String | Definition: Type. Value range: attachment: The metadata type is attachment. |
| category | String | Definition: Metadata type. Value range: Attachment: The metadata type is attachment. |
| issue_category | String | Definition: Work item type. Value range: N/A |
| status | String | Definition: Attachment status. Value range: N/A |
| description | String | Definition: Attachment description. Value range: N/A |
| modified_by | UserCommonVO object | Modifier. |
| created_by | UserCommonVO object | Definition: Creator. |
| domain_id | String | Definition: ID of the domain to which the project belongs. Value range: N/A |
| attachment_type | String | Definition: File type. Value range: N/A |
| created_date | String | Definition: Creation timestamp. Value range: N/A |
| storage_service | String | Definition: Name of the backend service that processes attachments. Value range: N/A |
| storage_id | String | Definition: Storage ID used in the database. Value range: N/A |
| delete_flag | Boolean | Definition: Deleted or not. Value range: false: not deleted true: deleted |
| filesize | Long | Definition: File size. Options: N/A |
| title | String | Definition: Actual name of the server. Value range: N/A |
| Parameter | Type | Description |
|---|---|---|
| user_id | String | Definition: User ID. Value range: N/A |
| user_num_id | Integer | Definition: Short ID of a user. Value range: N/A |
| user_name | String | Definition: Username. Value range: N/A |
| domain_id | String | Definition: ID of the domain to which the user belongs. Value range: N/A |
| domain_name | String | Definition: Tenant name. Value range: N/A |
| nick_name | String | Definition: User alias. Value range: N/A |
| role_id | String | Definition: Role ID. If a user has multiple roles in a project, use commas (,) to separate the values. Value range: N/A |
| role_name | String | Definition: Role name. If a user has multiple roles, use commas (,) to separate the values. Value range: N/A |
| image_id | String | Definition: User avatar. Value range: N/A |
| region | String | Definition: Region to which a user belongs. Value range: N/A |
| watcher | Integer | Definition: Observer. Value range: N/A |
| opinion | String | Definition: Review information. Value range: N/A |
| description | String | Definition: Description. Value range: N/A |
| owner | String | Definition: Current handler. Value range: N/A |
| ccbId | String | Definition: Review object ID. Value range: N/A |
| status | Integer | Definition: Status. Value range: N/A |
| has_removed | String | Definition: Whether the user has been removed from the project. Value range: N/A |
Status code: 400
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code. Value range: N/A |
| error_msg | String | Definition: Error description, which is a supplement to error_code. Value range: N/A |
Example Requests
Assume that the project ID is gdbdf969b32694524a949b5ef6b3e124a and the work item ID is 956239067176935400. The following is an example of uploading an image attachment named demo.PNG to the work item:
POST https://{endpoint}/v1/ipdprojectservice/projects/gdbdf969b32694524a949b5ef6b3e124a/issues/956239067176935400/attachments/upload
------WebKitFormBoundary1kuNerRnRVVybt65
Content-Disposition: form-data; name="attachment"; filename="demo.PNG"
Content-Type: image/png Example Responses
Status code: 200
Response to a successful request for uploading an attachment.
{
"status" : "success",
"message" : "",
"result" : [ {
"progress" : 100,
"id" : "1212813884362502144",
"workitem_id" : "1212811957668290561",
"associate_type" : null,
"disk_directory" : "/projects/687a0637cf814b65b77b3e781af19ab2/attachments/6b570776a30844e7b6361f00c2a1a5bf.xlsx",
"filesize" : "36449",
"store_filename" : "TTT.xlsx",
"title" : "6b570776a30844e7b6361f00c2a1a5bf.xlsx",
"type" : "attachment",
"category" : "Attachment",
"issue_category" : null,
"status" : null,
"description" : null,
"modified_by" : {
"watcher" : null,
"user_id" : "fcb28511450247ffbf78071035f9543c",
"user_num_id" : 13369,
"user_name" : "CodeArtsReq_GA2_MAX_Items",
"domain_id" : "cdf72eb7297642da8c4b0dffe4f4f14b",
"domain_name" : "CodeArtsReq_Test",
"nick_name" : "CodeArtsReq_GA2_MAX_Items",
"role_id" : null,
"role_name" : null,
"image_id" : null,
"region" : null,
"opinion" : null,
"description" : null,
"owner" : null,
"ccbId" : null,
"status" : 1,
"has_removed" : null
},
"created_by" : {
"watcher" : null,
"user_id" : "fcb28511450247ffbf78071035f9543c",
"user_num_id" : 13369,
"user_name" : "CodeArtsReq_GA2_MAX_Items",
"domain_id" : "cdf72eb7297642da8c4b0dffe4f4f14b",
"domain_name" : "CodeArtsReq_Test",
"nick_name" : "CodeArtsReq_GA2_MAX_Items",
"role_id" : null,
"role_name" : null,
"image_id" : null,
"region" : null,
"opinion" : null,
"description" : null,
"owner" : null,
"ccbId" : null,
"status" : 1,
"has_removed" : null
},
"domain_id" : "1212810843328520193",
"attachment_type" : "xlsx",
"created_date" : "1767086963022",
"storage_service" : "IPDProjectService",
"storage_id" : "6b570776a30844e7b6361f00c2a1a5bf",
"delete_flag" : false
} ]
} Status code: 400
Response to the attachment upload failure, such as no operation permission and the work item has been deleted.
{
"error_code" : "PM.02175145",
"error_msg" : "The work item has been deleted."
} SDK Sample Code
The SDK sample code is as follows.
Java
Assume that the project ID is gdbdf969b32694524a949b5ef6b3e124a and the work item ID is 956239067176935400. The following is an example of uploading an image attachment named demo.PNG to the work item:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.projectman.v4.region.ProjectManRegion; import com.huaweicloud.sdk.projectman.v4.*; import com.huaweicloud.sdk.projectman.v4.model.*; public class CreateIpdProjectIssueAttachmentSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); ProjectManClient client = ProjectManClient.newBuilder() .withCredential(auth) .withRegion(ProjectManRegion.valueOf("<YOUR REGION>")) .build(); CreateIpdProjectIssueAttachmentRequest request = new CreateIpdProjectIssueAttachmentRequest(); request.withProjectId("{project_id}"); request.withIssueId("{issue_id}"); try { CreateIpdProjectIssueAttachmentResponse response = client.createIpdProjectIssueAttachment(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
Python
Assume that the project ID is gdbdf969b32694524a949b5ef6b3e124a and the work item ID is 956239067176935400. The following is an example of uploading an image attachment named demo.PNG to the work item:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkprojectman.v4.region.projectman_region import ProjectManRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkprojectman.v4 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] credentials = BasicCredentials(ak, sk) client = ProjectManClient.new_builder() \ .with_credentials(credentials) \ .with_region(ProjectManRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateIpdProjectIssueAttachmentRequest() request.project_id = "{project_id}" request.issue_id = "{issue_id}" response = client.create_ipd_project_issue_attachment(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Go
Assume that the project ID is gdbdf969b32694524a949b5ef6b3e124a and the work item ID is 956239067176935400. The following is an example of uploading an image attachment named demo.PNG to the work item:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" projectman "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/projectman/v4" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/projectman/v4/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/projectman/v4/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") auth, err := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). SafeBuild() if err != nil { fmt.Println(err) return } hcClient, err := projectman.ProjectManClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). SafeBuild() if err != nil { fmt.Println(err) return } client := projectman.NewProjectManClient(hcClient) request := &model.CreateIpdProjectIssueAttachmentRequest{} request.ProjectId = "{project_id}" request.IssueId = "{issue_id}" response, err := client.CreateIpdProjectIssueAttachment(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
More
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
| Status Code | Description |
|---|---|
| 200 | Response to a successful request for uploading an attachment. |
| 400 | Response to the attachment upload failure, such as no operation permission and the work item has been deleted. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot