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

[question] [howto] How to post a file to Nucleus? #95

Open
mcdoolz opened this issue Jun 4, 2020 · 0 comments
Open

[question] [howto] How to post a file to Nucleus? #95

mcdoolz opened this issue Jun 4, 2020 · 0 comments

Comments

@mcdoolz
Copy link

mcdoolz commented Jun 4, 2020

I'm using Atlassian Nucleus and I've been trying to post my electron application release and failing.

I have a local Docker container set up for Nucleus and I can post releases using electron-forge; the files appear, versioned and ready to rock and roll.

I've written a javascript form and I've been attempting to post the release this way as I use electron-packager (electron-forge packages hit just south of a gigabyte while electron-packager prunes to under 300mb).

The form works well enough but I can't seem to post files to Nucleus.

This was my latest iteration:

<form id="release_form">
  <label for="server_address">Enter an address for an update server to post to.<br><sup>This defaults to localhost:3030</sup></label>
  <input id="server_address" type="text" placeholder="http://localhost:3030" />
  <label for="release_package">Select the folder to upload.</label>
  <input id="release_package" type="file" />
  <input id="submit_release" type="submit" />
</form>
<script>
  (function($) {
    const release_package = document.getElementById('release_package');
    const server_address = document.getElementById('server_address');
    const submit_release = document.getElementById('submit_release');

    $('#release_form').on('submit', function(e) {
      e.preventDefault();
      submit_release.disabled = true;
      if (release_package.value) {
        console.log(release_package.value);

        const data = new FormData();
        data.append('platform', 'darwin');
        data.append('arch', 'x64');
        data.append('version', '0.3.0');

        let reader = new FileReader();
        reader.onload = () => {
          data.append(`file`, reader.result);

          const config = {
            host: (server_address.value) ? server_address.value : 'http://localhost:3030',
            appId: '1',
            channelId: 'channel_id',
            token: 'token'
          }

          fetch(`${config.host}/rest/app/${config.appId}/channel/${config.channelId}/upload`, {
            headers: {
              'Authorization': config.token
            },
            method: 'POST',
            body: data,
          }).then((response) => {
            if (response.status !== 200) {
              console.error(`Unexpected response code from Nucleus: ${response.status}`);
            }
            console.log(response);
          }).finally(() => {
            submit_release.disabled = false;
          });
        }

        reader.readAsBinaryString(release_package.files[0]);

      }
    });
  })(jQuery);
</script>

This iteration comes after several other attempts using various approaches all of which were derived from the suggested example in Electron-Forge's NodeJS publishing code.

The above code results in a 500 error. Attempting to use release_package.files[0] directly results in a 400 error.

Any help would be greatly appreciated.

Edit:
Solved the issue; turns out, using Fetch, I wasn't seeing the error being returned by Nucleus, which asked for the version in the file name. The code posted above otherwise works perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant