文档首页/ 需求管理 CodeArts Req/ API参考/ API/ IPD附件管理/ 上传文件并关联工作项 - CreateIpdProjectIssueAttachment
更新时间:2026-02-13 GMT+08:00
分享

上传文件并关联工作项 - CreateIpdProjectIssueAttachment

功能介绍

需要给IPD项目下的工作项上传附件时,可调用此接口。用户可以通过项目ID和工作项ID,传入需要关联的文件,给该工作项关联附件。

调用方法

请参见如何调用API

授权信息

账号根用户具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备如下身份策略权限,更多的权限说明请参见权限和授权项

授权项

访问级别

资源类型(*为必须)

条件键

别名

依赖的授权项

codeartsreq:attachment:upload

Write

-

  • codeartsreq:Model

  • codeartsreq:ProjectId

-

-

URI

POST /v1/ipdprojectservice/projects/{project_id}/issues/{issue_id}/attachments/upload

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释

项目的32位uuid,项目唯一标识,通过查询项目列表接口获取,响应消息体中的project_id字段的值就是项目ID。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

issue_id

String

参数解释

工作项唯一ID。可以通过查询工作项列表或者查询树状工作接口获取,响应消息体中的id字段的值就是工作项ID。

约束限制

不涉及。

取值范围:

不涉及。

默认取值

不涉及。

请求参数

表2 FormData参数

参数

是否必选

参数类型

描述

attachment

File

参数解释:

附件。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

响应参数

状态码:200

表3 响应Body参数

参数

参数类型

描述

status

String

参数解释:

返回状态。

取值范围:

  • success:响应成功

  • error:响应失败

message

String

参数解释:

失败信息

取值范围:

不涉及

result

Array of AttachmentVoExt objects

参数解释:

附件上传信息

表4 AttachmentVoExt

参数

参数类型

描述

progress

Integer

参数解释:

上传进度

取值范围:

不涉及

id

String

参数解释:

附件ID

取值范围:

不涉及

workitem_id

String

参数解释:

工作项ID

取值范围:

不涉及

store_filename

String

参数解释:

服务器上实际名称

取值范围:

不涉及

associate_type

String

参数解释:

关联类型。

取值范围:

不涉及。

disk_directory

String

参数解释:

附件在服务器上的相对存储路径

取值范围:

不涉及

type

String

参数解释:

类别

取值范围:

  • attachment:标识元数据类型为附件

category

String

参数解释:

元数据类型

取值范围:

  • Attachment:标识元数据类型为附件

issue_category

String

参数解释:

工作项类型

取值范围:

不涉及

status

String

参数解释:

附件状态

取值范围:

不涉及

description

String

参数解释:

附件描述

取值范围:

不涉及

modified_by

UserCommonVO object

修改人信息

created_by

UserCommonVO object

参数解释:

创建人信息

domain_id

String

参数解释:

项目所属域ID

取值范围:

不涉及

attachment_type

String

参数解释:

文件类型

取值范围:

不涉及

created_date

String

参数解释:

创建时间戳

取值范围:

不涉及

storage_service

String

参数解释:

处理附件的后台服务名

取值范围:

不涉及

storage_id

String

参数解释:

数据库中使用的存储ID

取值范围:

不涉及

delete_flag

Boolean

参数解释:

迭代是否已经删除

取值范围:

  • false:未删除

  • true:已删除

filesize

Long

参数解释:

文件大小

取值范围:

不涉及

title

String

参数解释:

文件名

取值范围:

不涉及

表5 UserCommonVO

参数

参数类型

描述

user_id

String

参数解释:

用户ID。

取值范围:

不涉及。

user_num_id

Integer

参数解释:

用户短ID。

取值范围:

不涉及。

user_name

String

参数解释:

用户名称。

取值范围:

不涉及。

domain_id

String

参数解释:

用户所属域ID。

取值范围:

不涉及。

domain_name

String

参数解释:

租户名称。

取值范围:

不涉及。

nick_name

String

参数解释:

用户昵称。

取值范围:

不涉及。

role_id

String

参数解释:

角色ID,用户在项目中具有多个角色时用英文逗号分隔。

取值范围:

不涉及。

role_name

String

参数解释:

用户角色名称,多个角色用英文逗号分隔。

取值范围:

不涉及。

image_id

String

参数解释:

用户头像。

取值范围:

不涉及。

region

String

参数解释:

用户所属区域。

取值范围:

不涉及。

watcher

Integer

参数解释:

观察者。

取值范围:

不涉及。

opinion

String

参数解释:

评审信息。

取值范围:

不涉及。

description

String

参数解释:

描述。

取值范围:

不涉及。

owner

String

参数解释:

当前处理人。

取值范围:

不涉及。

ccbId

String

参数解释:

评审对象ID。

取值范围:

不涉及。

status

Integer

参数解释:

状态。

取值范围:

不涉及。

has_removed

String

参数解释:

用户是否已移出项目。

取值范围:

不涉及。

状态码:400

表6 响应Body参数

参数

参数类型

描述

error_code

String

参数解释:

错误码。

取值范围:

不涉及。

error_msg

String

参数解释:

错误描述,对error_code的补充解释。

取值范围:

不涉及。

请求示例

假设项目ID为gdbdf969b32694524a949b5ef6b3e124a,工作项ID为956239067176935400,给该工作项上传一个名为"demo.PNG"的图片附件,示例如下:

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

响应示例

状态码:200

上传附件成功的响应。

{
  "status" : "success",
  "message" : "",
  "result" : [ {
    "progress" : 100,
    "id" : "1210262357406371841",
    "workitem_id" : "1124065462758453249",
    "disk_directory" : "/projects/b7ea310baf1045cd9249950485d6233b/attachments/a6d3e9363de345c9a569266de33c183d.gz",
    "filesize" : "735205",
    "store_filename" : "resource_apigateway_ProjectManOpenApi-BRC_25.1027.1715.tar.gz",
    "title" : "a6d3e9363de345c9a569266de33c183d.gz",
    "type" : "attachment",
    "category" : "Attachment",
    "modified_by" : {
      "user_id" : "a360371833bf4c558f796fd707b44daf",
      "user_num_id" : 4091,
      "user_name" : "devcloud_devcloud_s00404480_01",
      "domain_id" : "4e919d73499648e3b0292cd3cbef806a",
      "domain_name" : "devcloud_devcloud_s00404480_01",
      "nick_name" : "修改昵称测试4"
    },
    "created_by" : {
      "user_id" : "a360371833bf4c558f796fd707b44daf",
      "user_num_id" : 4091,
      "user_name" : "devcloud_devcloud_s00404480_01",
      "domain_id" : "4e919d73499648e3b0292cd3cbef806a",
      "domain_name" : "devcloud_devcloud_s00404480_01",
      "nick_name" : "修改昵称测试4"
    },
    "domain_id" : "1117757213628080128",
    "attachment_type" : "gz",
    "created_date" : "1766478631489",
    "storage_service" : "IPDProjectService",
    "storage_id" : "a6d3e9363de345c9a569266de33c183d",
    "delete_flag" : false
  } ]
}

状态码:400

上传附件失败的响应,例如:无操作权限、工作项已删除等

{
  "error_code" : "PM.02175145",
  "error_msg" : "工作项已删除"
}

SDK代码示例

SDK代码示例如下。

Java

假设项目ID为gdbdf969b32694524a949b5ef6b3e124a,工作项ID为956239067176935400,给该工作项上传一个名为"demo.PNG"的图片附件,示例如下:

 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

假设项目ID为gdbdf969b32694524a949b5ef6b3e124a,工作项ID为956239067176935400,给该工作项上传一个名为"demo.PNG"的图片附件,示例如下:

 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

假设项目ID为gdbdf969b32694524a949b5ef6b3e124a,工作项ID为956239067176935400,给该工作项上传一个名为"demo.PNG"的图片附件,示例如下:

 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
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 := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := projectman.NewProjectManClient(
        projectman.ProjectManClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    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)
    }
}

更多

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

上传附件成功的响应。

400

上传附件失败的响应,例如:无操作权限、工作项已删除等

错误码

请参见错误码

相关文档