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

File upload example for javascript returns No file found in request. #66

Closed
LindaLawton opened this issue Apr 15, 2024 · 7 comments
Closed
Labels
component:quickstarts Issues/PR referencing quickstarts folder status:awaiting response Awaiting a response from the author status:stale Issue/PR is marked for closure due to inactivity type:bug Something isn't working

Comments

@LindaLawton
Copy link

LindaLawton commented Apr 15, 2024

I tried to run the file upload example for javascript

The file exits as i added a check for it

// Check if the file exists
if (!fs.existsSync(filePath)) {
    console.log(`File '${filePath}' does not exist` );
}

When i run the sample i get

GaxiosError: No file found in request.
    at Gaxios._request (C:\Development\Gemini\nodejs\gemini_samples_node\node_modules\gaxios\build\src\gaxios.js:144:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async JWT.requestAsync (C:\Development\Gemini\nodejs\gemini_samples_node\node_modules\google-auth-library\build\src\auth\oauth2client.js:405:18)
    at async run (C:\Development\Gemini\nodejs\gemini_samples_node\test2.js:30:36) {
  config: {
    url: 'https://generativelanguage.googleapis.com/upload/v1beta/files?uploadType=multipart',
    method: 'POST',
    userAgentDirectives: [
      {
        product: 'google-api-nodejs-client',
        version: '7.1.0',
        comment: 'gzip'
      }
    ],
    paramsSerializer: [Function (anonymous)],
    data: PassThrough {
      _readableState: ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: BufferList { head: null, tail: null, length: 0 },
        length: 0,
        pipes: [],
        flowing: false,
        ended: true,
        endEmitted: true,
        reading: false,
        constructed: true,
        sync: false,
        needReadable: false,
        emittedReadable: false,
        readableListening: false,
        resumeScheduled: false,
        errorEmitted: false,
        emitClose: true,
        autoDestroy: true,
        destroyed: true,
        errored: null,
        closed: true,
        closeEmitted: true,
        defaultEncoding: 'utf8',
        awaitDrainWriters: null,
        multiAwaitDrain: false,
        readingMore: false,
        dataEmitted: true,
        decoder: null,
        encoding: null,
        [Symbol(kPaused)]: true
      },
      _events: [Object: null prototype] {
        prefinish: [Function: prefinish],
        error: [Function (anonymous)]
      },
      _eventsCount: 2,
      _maxListeners: undefined,
      _writableState: WritableState {
        objectMode: false,
        highWaterMark: 16384,
        finalCalled: true,
        needDrain: false,
        ending: true,
        ended: true,
        finished: true,
        destroyed: true,
        decodeStrings: true,
        defaultEncoding: 'utf8',
        length: 0,
        writing: false,
        corked: 0,
        sync: false,
        bufferProcessing: false,
        onwrite: [Function: bound onwrite],
        writecb: null,
        writelen: 0,
        afterWriteTickInfo: null,
        buffered: [],
        bufferedIndex: 0,
        allBuffers: true,
        allNoop: true,
        pendingcb: 0,
        constructed: true,
        prefinished: true,
        errorEmitted: false,
        emitClose: true,
        autoDestroy: true,
        errored: null,
        closed: true,
        closeEmitted: true,
        [Symbol(kOnFinished)]: []
      },
      allowHalfOpen: true,
      _flush: [Function: flush],
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: null
    },
    headers: {
      'x-goog-api-client': 'gdcl/7.1.0 gl-node/18.16.1',
      'content-type': 'multipart/related; boundary=cf9e6ad4-9c0e-4e75-9a86-01de5c3e849f',
      'Accept-Encoding': 'gzip',
      'User-Agent': 'google-api-nodejs-client/7.1.0 (gzip)',
      'X-Goog-Api-Key': '[REDACTED]'
    },
    params: { uploadType: 'multipart' },
    validateStatus: [Function (anonymous)],
    retry: true,
    body: PassThrough {
      _readableState: ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: BufferList { head: null, tail: null, length: 0 },
        length: 0,
        pipes: [],
        flowing: false,
        ended: true,
        endEmitted: true,
        reading: false,
        constructed: true,
        sync: false,
        needReadable: false,
        emittedReadable: false,
        readableListening: false,
        resumeScheduled: false,
        errorEmitted: false,
        emitClose: true,
        autoDestroy: true,
        destroyed: true,
        errored: null,
        closed: true,
        closeEmitted: true,
        defaultEncoding: 'utf8',
        awaitDrainWriters: null,
        multiAwaitDrain: false,
        readingMore: false,
        dataEmitted: true,
        decoder: null,
        encoding: null,
        [Symbol(kPaused)]: true
      },
      _events: [Object: null prototype] {
        prefinish: [Function: prefinish],
        error: [Function (anonymous)]
      },
      _eventsCount: 2,
      _maxListeners: undefined,
      _writableState: WritableState {
        objectMode: false,
        highWaterMark: 16384,
        finalCalled: true,
        needDrain: false,
        ending: true,
        ended: true,
        finished: true,
        destroyed: true,
        decodeStrings: true,
        defaultEncoding: 'utf8',
        length: 0,
        writing: false,
        corked: 0,
        sync: false,
        bufferProcessing: false,
        onwrite: [Function: bound onwrite],
        writecb: null,
        writelen: 0,
        afterWriteTickInfo: null,
        buffered: [],
        bufferedIndex: 0,
        allBuffers: true,
        allNoop: true,
        pendingcb: 0,
        constructed: true,
        prefinished: true,
        errorEmitted: false,
        emitClose: true,
        autoDestroy: true,
        errored: null,
        closed: true,
        closeEmitted: true,
        [Symbol(kOnFinished)]: []
      },
      allowHalfOpen: true,
      _flush: [Function: flush],
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: null
    },
    responseType: 'unknown',
    errorRedactor: [Function: defaultErrorRedactor],
    retryConfig: {
      currentRetryAttempt: 0,
      retry: 3,
      httpMethodsToRetry: [ 'GET', 'HEAD', 'PUT', 'OPTIONS', 'DELETE' ],
      noResponseRetries: 2,
      statusCodesToRetry: [ [ 100, 199 ], [ 429, 429 ], [ 500, 599 ] ]
    }
  },
  response: {
    config: {
      url: 'https://generativelanguage.googleapis.com/upload/v1beta/files?uploadType=multipart',
      method: 'POST',
      userAgentDirectives: [
        {
          product: 'google-api-nodejs-client',
          version: '7.1.0',
          comment: 'gzip'
        }
      ],
      paramsSerializer: [Function (anonymous)],
      data: PassThrough {
        _readableState: ReadableState {
          objectMode: false,
          highWaterMark: 16384,
          buffer: BufferList { head: null, tail: null, length: 0 },
          length: 0,
          pipes: [],
          flowing: false,
          ended: true,
          endEmitted: true,
          reading: false,
          constructed: true,
          sync: false,
          needReadable: false,
          emittedReadable: false,
          readableListening: false,
          resumeScheduled: false,
          errorEmitted: false,
          emitClose: true,
          autoDestroy: true,
          destroyed: true,
          errored: null,
          closed: true,
          closeEmitted: true,
          defaultEncoding: 'utf8',
          awaitDrainWriters: null,
          multiAwaitDrain: false,
          readingMore: false,
          dataEmitted: true,
          decoder: null,
          encoding: null,
          [Symbol(kPaused)]: true
        },
        _events: [Object: null prototype] {
          prefinish: [Function: prefinish],
          error: [Function (anonymous)]
        },
        _eventsCount: 2,
        _maxListeners: undefined,
        _writableState: WritableState {
          objectMode: false,
          highWaterMark: 16384,
          finalCalled: true,
          needDrain: false,
          ending: true,
          ended: true,
          finished: true,
          destroyed: true,
          decodeStrings: true,
          defaultEncoding: 'utf8',
          length: 0,
          writing: false,
          corked: 0,
          sync: false,
          bufferProcessing: false,
          onwrite: [Function: bound onwrite],
          writecb: null,
          writelen: 0,
          afterWriteTickInfo: null,
          buffered: [],
          bufferedIndex: 0,
          allBuffers: true,
          allNoop: true,
          pendingcb: 0,
          constructed: true,
          prefinished: true,
          errorEmitted: false,
          emitClose: true,
          autoDestroy: true,
          errored: null,
          closed: true,
          closeEmitted: true,
          [Symbol(kOnFinished)]: []
        },
        allowHalfOpen: true,
        _flush: [Function: flush],
        [Symbol(kCapture)]: false,
        [Symbol(kCallback)]: null
      },
      headers: {
        'x-goog-api-client': 'gdcl/7.1.0 gl-node/18.16.1',
        'content-type': 'multipart/related; boundary=cf9e6ad4-9c0e-4e75-9a86-01de5c3e849f',
        'Accept-Encoding': 'gzip',
        'User-Agent': 'google-api-nodejs-client/7.1.0 (gzip)',
        'X-Goog-Api-Key': '[REDACTED]'
      },
      params: { uploadType: 'multipart' },
      validateStatus: [Function (anonymous)],
      retry: true,
      body: PassThrough {
        _readableState: ReadableState {
          objectMode: false,
          highWaterMark: 16384,
          buffer: BufferList { head: null, tail: null, length: 0 },
          length: 0,
          pipes: [],
          flowing: false,
          ended: true,
          endEmitted: true,
          reading: false,
          constructed: true,
          sync: false,
          needReadable: false,
          emittedReadable: false,
          readableListening: false,
          resumeScheduled: false,
          errorEmitted: false,
          emitClose: true,
          autoDestroy: true,
          destroyed: true,
          errored: null,
          closed: true,
          closeEmitted: true,
          defaultEncoding: 'utf8',
          awaitDrainWriters: null,
          multiAwaitDrain: false,
          readingMore: false,
          dataEmitted: true,
          decoder: null,
          encoding: null,
          [Symbol(kPaused)]: true
        },
        _events: [Object: null prototype] {
          prefinish: [Function: prefinish],
          error: [Function (anonymous)]
        },
        _eventsCount: 2,
        _maxListeners: undefined,
        _writableState: WritableState {
          objectMode: false,
          highWaterMark: 16384,
          finalCalled: true,
          needDrain: false,
          ending: true,
          ended: true,
          finished: true,
          destroyed: true,
          decodeStrings: true,
          defaultEncoding: 'utf8',
          length: 0,
          writing: false,
          corked: 0,
          sync: false,
          bufferProcessing: false,
          onwrite: [Function: bound onwrite],
          writecb: null,
          writelen: 0,
          afterWriteTickInfo: null,
          buffered: [],
          bufferedIndex: 0,
          allBuffers: true,
          allNoop: true,
          pendingcb: 0,
          constructed: true,
          prefinished: true,
          errorEmitted: false,
          emitClose: true,
          autoDestroy: true,
          errored: null,
          closed: true,
          closeEmitted: true,
          [Symbol(kOnFinished)]: []
        },
        allowHalfOpen: true,
        _flush: [Function: flush],
        [Symbol(kCapture)]: false,
        [Symbol(kCallback)]: null
      },
      responseType: 'unknown',
      errorRedactor: [Function: defaultErrorRedactor]
    },
    data: 'No file found in request.',
    headers: {
      'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
      connection: 'close',
      'content-length': '25',
      'content-type': 'text/plain; charset=utf-8',
      date: 'Mon, 15 Apr 2024 12:38:14 GMT',
      server: 'UploadServer',
      'x-guploader-uploadid': 'ABPtcPqNkgTHmrQKds3j_Ta0oLJiLONuY30frVrqh61kdQLK-YokDMT1RFx5H3EY38h3ivp7bvo'
    },
    status: 400,
    statusText: 'Bad Request',
    request: {
      responseURL: 'https://generativelanguage.googleapis.com/upload/v1beta/files?uploadType=multipart'
    }
  },
  error: undefined,
  status: 400,
  [Symbol(gaxios-gaxios-error)]: '6.4.0'
}

Update

I did find that this works loading just the file path.

const media = {
        mimeType: mime.lookup(filePath),
        body: filePath,
    };

It seams its the loading the stream thats not working.

@TYMichaelChen
Copy link
Collaborator

Hi Linda - thanks for reporting this. I'd like to understand the issue with fs.createReadStream a bit more. Can you try running the sample code from the repo and see if that succeeds? If not can you provide the error and what env you're running with? readme

@ymodak ymodak added component:quickstarts Issues/PR referencing quickstarts folder type:bug Something isn't working labels Apr 15, 2024
@markmcd
Copy link
Member

markmcd commented Aug 27, 2024

Hey @LindaLawton - could you provide @TYMichaelChen with any more info?

@markmcd markmcd added the status:awaiting response Awaiting a response from the author label Aug 27, 2024
@LindaLawton
Copy link
Author

sorry @markmcd I havent touched this since then. I dont use env vars as there is really no need when you are passing the api key directly.

 API_KEY = process.env.GOOGLE_API_KEY;

Copy link

Marking this issue as stale since it has been open for 14 days with no activity. This issue will be closed if no further activity occurs.

@github-actions github-actions bot added the status:stale Issue/PR is marked for closure due to inactivity label Sep 12, 2024
@markmcd
Copy link
Member

markmcd commented Sep 12, 2024

sorry @markmcd I havent touched this since then. I dont use env vars as there is really no need when you are passing the api key directly.

I think @TYMichaelChen meant the general environment, not the specific vars. e.g. I tested on Linux with Node 18.19 and it worked fine.

It looks like you're using Windows - the only thing I can think of is that the / in the path might cause issues. Though you say that fs.existsSync succeeds, and the error is not Error: ENOENT: no such file or directory when opening the stream.

See if #279 helps?

@github-actions github-actions bot removed the status:stale Issue/PR is marked for closure due to inactivity label Sep 12, 2024
Copy link

Marking this issue as stale since it has been open for 14 days with no activity. This issue will be closed if no further activity occurs.

@github-actions github-actions bot added the status:stale Issue/PR is marked for closure due to inactivity label Sep 26, 2024
Copy link

github-actions bot commented Oct 9, 2024

This issue was closed because it has been inactive for 27 days. Please post a new issue if you need further assistance. Thanks!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:quickstarts Issues/PR referencing quickstarts folder status:awaiting response Awaiting a response from the author status:stale Issue/PR is marked for closure due to inactivity type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants