Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "fileInfo" argument to startLargeFile #139

Open
tapetkabinett opened this issue Jul 3, 2024 · 0 comments
Open

Add "fileInfo" argument to startLargeFile #139

tapetkabinett opened this issue Jul 3, 2024 · 0 comments

Comments

@tapetkabinett
Copy link

In the Backblaze B2 docs we can see that the b2_start_large_file endpoint has a "fileInfo" argument. Without this argument, we cannot set headers such as Content-Disposition on the uploaded file, which makes it impossible to specify that we want the file to be an attachment.

I'm requesting the following changes be made to the backblaze-b2 package:
lib>actions>file.js

  1. Change the following code:
exports.startLargeFile = function(b2, args) {
    const options = {
        url: endpoints(b2).startLargeFileUrl,
        method: 'POST',
        headers: utils.getAuthHeaderObjectWithToken(b2),
        data: {
            bucketId: args.bucketId,
            fileName: args.fileName,
            contentType: args.contentType || 'b2/x-auto'
        }
    };

    // merge order matters here: later objects override earlier objects
    return request.sendRequest(_.merge({},
        _.get(args, 'axios', {}),
        options,
        _.get(args, 'axiosOverride', {})
    ));
};

to

exports.startLargeFile = function (b2, args) {
  const options = {
    url: endpoints(b2).startLargeFileUrl,
    method: 'POST',
    headers: utils.getAuthHeaderObjectWithToken(b2),
    data: {
      bucketId: args.bucketId,
      fileName: args.fileName,
      fileInfo: args.fileInfo,
      contentType: args.contentType || 'b2/x-auto',
    },
  };

  // merge order matters here: later objects override earlier objects
  return request.sendRequest(
    _.merge(
      {},
      _.get(args, 'axios', {}),
      options,
      _.get(args, 'axiosOverride', {})
    )
  );
};

And the following changes be made to the @types/backblaze-b2 package:
index.d.ts

  1. Add one of the following types:
interface StartLargeFileOpts extends CommonArgs {
    bucketId: string;
    fileName: string;
    fileInfo?: {
        "b2-content-disposition"?: string;
        "b2-content-language"?: string;
        "b2-expires"?: string;
        "b2-cache-control"?: string;
        "b2-content-encoding"?: string;
    } | undefined;
}

or

interface StartLargeFileOpts extends CommonArgs {
    bucketId: string;
    fileName: string;
    fileInfo?: Record<string, any> | undefined;
}
  1. Change the following type:
    startLargeFile(opts: { bucketId: string; fileName: string } & CommonArgs): Promise<StandardApiResponse>;
    to
    startLargeFile(opts: StartLargeFileOpts): Promise<StandardApiResponse>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant