Azure / Azurite

A lightweight server clone of Azure Storage that simulates most of the commands supported by it with minimal dependencies
MIT License
1.8k stars 320 forks source link

Getting `error: ErrorMiddleware: Set HTTP body: undefined` when uploading a blob #2464

Closed sfali closed 1 week ago

sfali commented 2 weeks ago

Which service(blob, file, queue, table) does this issue concern?

Blob

Which version of the Azurite was used?

3.30.0

Where do you get Azurite? (npm, DockerHub, NuGet, Visual Studio Code Extension)

NPM and Docker

What's the Node.js version?

v20.17.0

What problem was encountered?

Getting following error when try to upload a blob:

2024-09-04T20:19:36.504Z     info: AccountDataStore:init() Fallback to default emulator account devstoreaccount1.
2024-09-04T20:19:51.002Z 82d9a1f2-2753-499c-9fd3-30375560a4cf info: BlobStorageContextMiddleware: RequestMethod=PUT RequestURL=http://127.0.0.1/test-container/testpng RequestHeaders:{"host":"127.0.0.1:10000","date":"Wed, 04 Sep 2024 20:19:50 GMT","authorization":"SharedKey devstoreaccount1:x9IH9a9JGa+4MfmfC+LvRVtws+SR5NlYMWxKOWhoh7g=","content-length":"1193556","if-none-match":"*","x-ms-version":"2024-08-04","content-type":"application/octet-stream","x-ms-client-request-id":"5d686006-5d4b-49b0-9de1-41e99de712f3","x-ms-blob-type":"BlockBlob","accept":"application/xml","user-agent":"azsdk-java-azure-storage-blob/12.27.0 (17.0.12; Mac OS X; 14.6.1)"} ClientIP=127.0.0.1 Protocol=http HTTPVersion=1.1
2024-09-04T20:19:51.002Z 82d9a1f2-2753-499c-9fd3-30375560a4cf info: BlobStorageContextMiddleware: Account=test-container Container=testpng Blob=
2024-09-04T20:19:51.002Z 82d9a1f2-2753-499c-9fd3-30375560a4cf verbose: DispatchMiddleware: Dispatching request...
2024-09-04T20:19:51.003Z 82d9a1f2-2753-499c-9fd3-30375560a4cf error: DispatchMiddleware: Incoming URL doesn't match any of swagger defined request patterns.
2024-09-04T20:19:51.003Z 82d9a1f2-2753-499c-9fd3-30375560a4cf error: ErrorMiddleware: Received a MiddlewareError, fill error information to HTTP response
2024-09-04T20:19:51.003Z 82d9a1f2-2753-499c-9fd3-30375560a4cf error: ErrorMiddleware: ErrorName=UnsupportedRequestError ErrorMessage=Incoming URL doesn't match any of swagger defined request patterns.  ErrorHTTPStatusCode=400 ErrorHTTPStatusMessage=undefined ErrorHTTPHeaders=undefined ErrorHTTPBody=undefined ErrorStack="UnsupportedRequestError: Incoming URL doesn't match any of swagger defined request patterns.\n    at dispatchMiddleware (/Users/sfali/.nvm/versions/node/v20.17.0/lib/node_modules/azurite/dist/src/blob/generated/middleware/dispatch.middleware.js:41:30)\n    at /Users/sfali/.nvm/versions/node/v20.17.0/lib/node_modules/azurite/dist/src/blob/generated/ExpressMiddlewareFactory.js:50:47\n    at Layer.handle [as handle_request] (/Users/sfali/.nvm/versions/node/v20.17.0/lib/node_modules/azurite/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/Users/sfali/.nvm/versions/node/v20.17.0/lib/node_modules/azurite/node_modules/express/lib/router/index.js:328:13)\n    at /Users/sfali/.nvm/versions/node/v20.17.0/lib/node_modules/azurite/node_modules/express/lib/router/index.js:286:9\n    at Function.process_params (/Users/sfali/.nvm/versions/node/v20.17.0/lib/node_modules/azurite/node_modules/express/lib/router/index.js:346:12)\n    at next (/Users/sfali/.nvm/versions/node/v20.17.0/lib/node_modules/azurite/node_modules/express/lib/router/index.js:280:10)\n    at blobStorageContextMiddleware (/Users/sfali/.nvm/versions/node/v20.17.0/lib/node_modules/azurite/dist/src/blob/middlewares/blobStorageContext.middleware.js:137:5)\n    at /Users/sfali/.nvm/versions/node/v20.17.0/lib/node_modules/azurite/dist/src/blob/middlewares/blobStorageContext.middleware.js:15:16\n    at Layer.handle [as handle_request] (/Users/sfali/.nvm/versions/node/v20.17.0/lib/node_modules/azurite/node_modules/express/lib/router/layer.js:95:5)"
2024-09-04T20:19:51.003Z 82d9a1f2-2753-499c-9fd3-30375560a4cf error: ErrorMiddleware: Set HTTP code: 400
2024-09-04T20:19:51.003Z 82d9a1f2-2753-499c-9fd3-30375560a4cf error: ErrorMiddleware: Set HTTP body: undefined
2024-09-04T20:19:51.003Z 82d9a1f2-2753-499c-9fd3-30375560a4cf info: EndMiddleware: End response. TotalTimeInMS=1 StatusCode=400 StatusMessage=undefined Headers={"server":"Azurite-Blob/3.32.0"}

Any idea what's going on?

My code is following:

def putBlob(filePath: String): Unit = {
    val path = Paths.get(filePath)
    val data = BinaryData.fromFile(path)
    val builder = new BlobServiceClientBuilder()
      .endpoint("http://127.0.0.1:10000")
      .credential(
        new StorageSharedKeyCredential(
          "devstoreaccount1",
          "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
        )
      )
      .buildClient()

    val client = builder.getBlobContainerClient(ContainerName).getBlobClient("testpng")
    client.upload(data)
  }

On a separate issue cannot use . in the blob name, test.png will not work, hence using testpng as blob name.

Steps to reproduce the issue?

If possible, please provide the debug log using the -d parameter, replacing \<pathtodebuglog> with an appropriate path for your OS, or review the instructions for docker containers:

-d "<pathtodebuglog>"

Please be sure to remove any PII or sensitive information before sharing!
The debug log will log raw request headers and bodies, so that we can replay these against Azurite using REST and create tests to validate resolution.

Have you found a mitigation/solution?

None

sfali commented 2 weeks ago

Forgot to mention the data does exist, file is not empty

sfali commented 2 weeks ago

One more thing to add I am using Java API

blueww commented 2 weeks ago

@EmmaZhu Would you please help to look?

@sfali From debug log, we can see the request Uri is invalid "http://127.0.0.1/test-container/testpng", it missed the storage account name. The Uri should look like "http://127.0.0.1/test-container/[AccountName]/testpng"

sfali commented 2 weeks ago

Thanks @EmmaZhu , account name was definitely missing. I can confirm it is working as expected

EmmaZhu commented 1 week ago

Close the issue now. Any further assistant required, please feel free to reopen it.