Skip to content

Bug: Twitter Plugin Media upload results in HTTP 400 Bad Request #107

@MHHukiewitz

Description

@MHHukiewitz
Twitter upload error details: {"error":"Error: Bad Request","stack":"Error: Error: Bad Request
    at <anonymous> ([REDACTED]/virtuals-agent/node_modules/@virtuals-protocol/game-twitter-plugin/dist/index.js:400:19)
    at fulfilled ([REDACTED]/virtuals-agent/node_modules/@virtuals-protocol/game-twitter-plugin/dist/index.js:50:24)
    at processTicksAndRejections (:12:39)","blobSize":845517,"blobType":"image/png"}

If I do something wrong, it would be nice to have a working example for the media upload with the twitter plugin itself, as it is otherwise undocumented.

            // Get the specific plot using fetch
            const response = await fetch(url, {
                headers: {
                    'Accept': 'image/png'
                }
            });
            const data = await response.arrayBuffer();

            // Convert the response to a blob with proper type
            const plotBlob = new Blob([data], { 
                type: 'image/png',
                endings: 'native'
            });
            const plotSize = plotBlob.size;

            // Check size limit
            if (plotSize > 5 * 1024 * 1024) {
                throw new Error("Plot size exceeds 5MB limit");
            }

            // Upload to Twitter
            try {
                // Create FormData with proper multipart boundaries
                const formData = new FormData();
                
                // Add the file with proper content type
                formData.append('file', plotBlob, `${plot_name}.png`);
                
                // Upload using the Twitter client
                const mediaId = await gameTwitterClient.uploadMedia(plotBlob);
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions