misskey apiで画像をアップロードする方法

:::note info
[zenn](https://zenn.dev/potetotown/articles/8ab5035019c6c6)のやつと同じです
:::

:::note warn
 misskey apiで画像アップロードをするときにはまったのでメモ
~~なんでどこにも情報がないんでしょうね~~
:::


## 結論
結論だけ知りたい人もいると思うので先に書きます。
**/api/drive/files/create**にfileを**multipart/form-data**でfileを送って
そこで帰ってきた**id**を使う

![](https://storage.googleapis.com/zenn-user-upload/111e3f3f58f3-20241128.png)

で送信して帰ってきた
```json
{
    "id": "a14e42mavoqa001g", //* ここを使う
    "createdAt": "2024-11-28T04:39:52.642Z",
    "name": "レコーディング 2024-11-01 221803.gif",
    "type": "image/gif",
    "md5": "745799dd651cc880bdf4cd799f533e28",
    "size": 400372,
    "isSensitive": false,
    "blurhash": "eL85Zgt7bGf+j[?^t6bFbHj[.ls:aybHj@.Ss:f6a#ja.Soff6f8ja",
    "properties": {
        "width": 2880,
        "height": 1698
    },
    "url": "https://media.misskeyusercontent.jp/io/2fdb7d7a-bc8e-48e8-a56b-f0c9b17d6f93.gif",
    "thumbnailUrl": "https://media.misskeyusercontent.jp/io/thumbnail-03c38e24-9a67-4250-a2c4-5dbc6457ef39.webp",
    "comment": null,
    "folderId": null,
    "folder": null,
    "userId": null,
    "user": null
}
```
さっき帰ってきたIdを使って**notes/create**にpostするだけ
![](https://storage.googleapis.com/zenn-user-upload/8e0fab763641-20241128.png)
そうするとこうなる
```json
{
    "createdNote": {
        "id": "a14e68cumipk01z5",
        "createdAt": "2024-11-28T04:41:33.390Z",
        "userId": "9bg3oo1vxg",
        "user": {
            "id": "9bg3oo1vxg",
            "name": "ぽてと:verified_blue:",
            "username": "poteto",
            "host": null,
            "avatarUrl": "https://misskey.io/identicon/poteto@misskey.io",
            "avatarBlurhash": null,
            "avatarDecorations": [],
            "isBot": false,
            "isCat": false,
            "emojis": {},
            "onlineStatus": "online",
            "badgeRoles": []
        },
        "text": "test file upload by api",
        "cw": null,
        "visibility": "public",
        "localOnly": false,
        "reactionAcceptance": null,
        "renoteCount": 0,
        "repliesCount": 0,
        "reactionCount": 0,
        "reactions": {},
        "reactionEmojis": {},
        "fileIds": [
            "a14e42mavoqa001g"
        ],
        "files": [
            {
                "id": "a14e42mavoqa001g",
                "createdAt": "2024-11-28T04:39:52.642Z",
                "name": "レコーディング 2024-11-01 221803.gif",
                "type": "image/gif",
                "md5": "745799dd651cc880bdf4cd799f533e28",
                "size": 400372,
                "isSensitive": false,
                "blurhash": "eL85Zgt7bGf+j[?^t6bFbHj[.ls:aybHj@.Ss:f6a#ja.Soff6f8ja",
                "properties": {
                    "width": 2880,
                    "height": 1698
                },
                "url": "https://media.misskeyusercontent.jp/io/2fdb7d7a-bc8e-48e8-a56b-f0c9b17d6f93.gif",
                "thumbnailUrl": "https://media.misskeyusercontent.jp/io/thumbnail-03c38e24-9a67-4250-a2c4-5dbc6457ef39.webp",
                "comment": null,
                "folderId": null,
                "folder": null,
                "userId": "9bg3oo1vxg",
                "user": null
            }
        ],
        "replyId": null,
        "renoteId": null,
        "clippedCount": 0
    }
}
```
そうすると
![](https://storage.googleapis.com/zenn-user-upload/837dc72bcec3-20241128.png)
のようになる