Skip to content

Commit

Permalink
Added returnFullMediaData parameter to v1 uploadMedia (#509)
Browse files Browse the repository at this point in the history
Add returnFullMediaData parameter to v1.uploadMedia

---------

Co-authored-by: Paul-Louis HERY <[email protected]>
  • Loading branch information
yangpten and PLhery authored Jan 19, 2024
1 parent 38f87ec commit a5f13c7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/v1/client.v1.write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,10 @@ export default class TwitterApiv1ReadWrite extends TwitterApiv1ReadOnly {
*
* @param options.target Target type `tweet` or `dm`. Defaults to `tweet`.
* You must specify it if you send a media to use in DMs.
*
* @param returnFullMediaData If set to true, returns the whole media information instead of just the media_id
*/
public async uploadMedia(file: TUploadableMedia, options: Partial<UploadMediaV1Params> = {}) {
public async uploadMedia(file: TUploadableMedia, options: Partial<UploadMediaV1Params> = {}, returnFullMediaData = false) {
const chunkLength = options.chunkLength ?? (1024 * 1024);

const { fileHandle, mediaCategory, fileSize, mimeType } = await this.getUploadMediaRequirements(file, options);
Expand Down Expand Up @@ -379,7 +381,11 @@ export default class TwitterApiv1ReadWrite extends TwitterApiv1ReadOnly {
}

// Video is ready, return media_id
return fullMediaData.media_id_string;
if (returnFullMediaData) {
return fullMediaData;
} else {
return fullMediaData.media_id_string;
}
} finally {
// Close file if any
if (typeof file === 'number') {
Expand Down

0 comments on commit a5f13c7

Please sign in to comment.