8000 Upload de Arquivos retorna sucesso mesmo quando falha o update no registro · Issue #234 · konecty/Konecty · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Upload de Arquivos retorna sucesso mesmo quando falha o update no registro #234
Open
@marcusdemoura

Description

@marcusdemoura

script para simular:

import { KonectyClient } from '@konecty/sdk/Client';
import { FilesManager } from '@konecty/sdk/FilesManager';
import { KonectyDocument } from '@konecty/sdk/Module';

const konectyConfig = {
  endpoint: 'https://hub.konecty.dev',
  accessKey:
  files: {
    providerUrl: 'https://hub.konecty.dev',
  }
};

const main = async () => {

  // Cria uma instância do KonectyClient
  // Encontra o WebElement que vai receber o arquivo
  const konectyClient = new KonectyClient(konectyConfig);
  console.log('creating webElement');
  const resultFindWebElement = (await konectyClient.create("WebElement", {
        status: "Ativo",
        name: "Teste de upload",
        type: "HTML",
      }));
  const webElement: KonectyDocument | null = resultFindWebElement?.data?.[0] ?? null;

  if(webElement) {
    // Cria um arquivo CSV com números aleatórios
    const csvContent = [
          'Random,Numbers',
          ...Array.from({ length: 10 }, () => [Math.floor(Math.random() * 1000000),Math.floor(Math.random() * 1000000)].join(',')),
      ].join('\n');

    // Cria um FormData com o arquivo CSV usando Blob
    const formData = new FormData();
    const blob = new Blob([csvContent], { type: 'text/csv' });
    formData.append('file', blob, 'random_numbers.csv');

    // Cria uma instância do FilesManager//
    const filesManager = new FilesManager(konectyConfig, [], {
        metaObject: "WebElement",
        fieldName: "file",
        recordId: webElement._id,
        _updatedAt: webElement._updatedAt,
    });

    // Faz o upload do arquivo CSV//
    const result = await filesManager.upload(formData);
    if (result.success) {
        console.log('File uploaded successfully:', result.data);
    } else {
        console.error('Upload failed:', result.errors);
    }

    const resultFindWebElement = await konectyClient.find("WebElement", {
      filter: {
        conditions: [
          { term: "_id", operator: "equals", value: webElement._id },
        ],
      },
      fields: ["file"],
    });
    console.log('webElement found', resultFindWebElement);
  } else {
    console.error('WebElement not found');
  }

}

main();

Com um log adicionado no sdk
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0