Skip to main content
Glama

putObjectSourceUrl

Downloads files from a URL and uploads them to cloud storage buckets for automated file transfer and management.

Instructions

通过 url下载文件并将文件上传到存储桶

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceUrlYes可下载的文件 url
fileNameNo文件名 (存在存储桶里的名称)
targetDirNo目标目录 (存在存储桶的哪个目录)

Implementation Reference

  • Core handler implementation: downloads file from sourceUrl using axios stream, generates filename if needed, builds COS path, and uploads via cos.putObject using PassThrough stream.
    async uploadFileSourceUrl(params: UploadFileParams) {
      // 验证并解析参数
      const validParams = UploadFileParamsSchema.parse(params);
      const { targetDir = '', fileName, sourceUrl } = validParams;
      try {
        const response = await axios({
          method: 'get',
          url: sourceUrl,
          responseType: 'stream'
        });
        const actualFileName = fileName ? fileName : generateOutPutFileId('');
        const cosPath = this.buildCosPath(actualFileName, targetDir);
        const req = response.data;
        const passThrough = new PassThrough();
        const result = await this.cos.putObject({
          Bucket: this.bucket,
          Region:this.region,
          Key: cosPath,
          Body: req.pipe(passThrough),
        });
        return {
          isSuccess: true,
          message: '上传成功',
          data: result,
        };
      } catch (error) {
        return {
          isSuccess: false,
          message: '上传失败',
          data: error,
        };
      }
    }
  • src/server.ts:221-248 (registration)
    MCP tool registration for 'putObjectSourceUrl', defines input schema with Zod and inline handler that delegates to CosService.uploadFileSourceUrl
    server.tool(
      'putObjectSourceUrl',
      '通过 url下载文件并将文件上传到存储桶',
      {
        sourceUrl: z.string().describe('可下载的文件 url'),
        fileName: z.string().optional().describe('文件名 (存在存储桶里的名称)'),
        targetDir: z
          .string()
          .optional()
          .describe('目标目录 (存在存储桶的哪个目录)'),
      },
      async ({ sourceUrl, fileName, targetDir}) => {
        const res = await COSInstance.uploadFileSourceUrl({
          targetDir,
          fileName,
          sourceUrl,
        });
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(res.data, null, 2),
            },
          ],
          isError: !res.isSuccess,
        };
      },
    );
  • Zod schema used in the handler for validating upload parameters including sourceUrl.
    export const UploadFileParamsSchema = z.object({
      filePath: z.string().optional(),
      targetDir: z.string().optional(),
      fileName: z.string().optional(),
      sourceUrl: z.string().optional()
    });
    export type UploadFileParams = z.infer<typeof UploadFileParamsSchema>;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/xiaomizhoubaobei/MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server