Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
2.03k stars 1.19k forks source link

I want to be able to upload the file directly to the application for translation instantly for a single document and not the file path #30797

Open rahmlad-aramide opened 3 weeks ago

rahmlad-aramide commented 3 weeks ago
          > Hello @rahmlad-aramide , you can provide a file path and then read and feed the contents of that file into the body parameter. For example: `// Replace 'filePath' with the path to your file const filePath = 'd:/testdocs/test-input.txt'; // Read the contents of the file asynchronously const fileContent = await readFileAsync(filePath, 'utf8');
const options: DocumentTranslateParameters = {
  queryParameters: {
    targetLanguage: "hi",
  },
  contentType: "multipart/form-data",
  body: [
    {
      name: "document",
      body: fileContent,
      filename: "test-input.txt",
      contentType: "text/plain", 
    },
  ],
};`

If you have a file in Azure blob, and want that to be translated into the right format, then you can use the example from here: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-document-rest/samples/v1-beta/typescript/src/batchDocumentTranslation.ts

That's the challenge I'm facing, because I'm trying to integrate it into my frontend application whereby the user will upload the file and accessing the absolute file path of a user's uploaded file directly in the browser is not possible due to security reasons. Browsers do not expose the information to web applications to protect user privacy and system security. Likewise, using the batch translation, the output file is not produced instantly, or is it possible that I provide the URL to the azure blob storage to the synchronous file translator after uploading it there or there's no solution at all? Thanks in advance for your help.

cc: @hamshavathimunibyraiah

Originally posted by @rahmlad-aramide in https://github.com/Azure/azure-sdk-for-js/issues/30312#issuecomment-2217103184

github-actions[bot] commented 3 weeks ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

rahmlad-aramide commented 3 weeks ago

Meanwhile, after I tried to use the method that @hamshavathimunibyraiah gave above, for docx, pptx and msg files, I'm not able to open the resulting documents, I'm getting: Screenshot 2024-08-19 140324

and this is what the content is showing: Screenshot 2024-08-19 140526

but working fine for HTML and plain text

rahmlad-aramide commented 3 weeks ago

For docx: image