GCloud storage download incomplete on GCE with NodeJS - node.js

I'm using GCloud version 0.18.0. On my dev PC, I actually download very well file on Google Storage. But once the script is running on a Google Compute Engine, the download start and says it's complete but it's not. It's a log file so when I'm checking the downloaded log file, I see it's not completed. The beginning of the file is there.
I made so much search and no body looks like to have my problem.
var gcloud = require('gcloud')({projectId: project_id});
var bucket = google.storage.bucket('logs');
var log_one = {filename: 'test.log'};
bucket.file(log_one.filename).download({destination: './tmp/processing_' + log_one.filename}, function(err) {
if (err.code == 403 || err.code == 404 || err.message) {
console.log(err);
console.log("Error after bucket.file.download");
return;
}
console.log("Downloaded file " + log_one.filename + " completed");
// Do stuff on the log file <-- Which is here the file is incomplete on GCE
});
The instance can talk with all Google API and anyway, it downloads a part of the log file.
I also tried to put a timer to give time to finish to write the file or something like that. No success. I'm never asking for help on forum, because I'm always finding a solution. But this one, I need help.

Since 0.18.0, we've run into a few issues related to streams & complete events. Upgrading to the latest version, 0.24.1, will likely magically resolve the issue.

Related

Uploading a file with Nightwatch and Browser Stack / Selenium Grid

I'm trying to upload a file in a nightwatch test that is being run on Browserstack in IE11. Here is what I have:
browser.execute(function (data) {
const el = document.querySelector('input#fileUpload');
el.style.display = "block";
el.removeAttribute('multiple');
}, []);
browser.setValue('input#fileUpload', require('path').resolve(__dirname + '/upload-files/test-doc.pdf'))
The error is a file not found issue, it works fine when being run on Chrome locally. Searching around, it seems like I need to upload the file to BS first, I found this gist and this PR but neither worked for me.
Since the file is not present on the machine of BrowserStack you might be encountering this error. You will need to use the 'setFileDetector' method provided by Selenium to upload a local file to remote grid. More details can be found on their documentation here - https://www.browserstack.com/automate/node#enhancements-uploads-downloads

problems uploading xslx file in body of post request to .net core app on aws-lambda

I'm trying to send a post request with postman to our AWS-Lambda server. Let me first state that, when running the web-server on my laptop using the Visual studio debugger, everything works fine. When trying to do exactly the same but to the url of the AWS-Lambda i'm getting the following errors when shifting through the logging:
when uploading the normal xlsx file (it's a size of 593kb)
Split or spanned archives are not supported.
When uploading the same file but with a few worksheet removed (because i thought maybe the size is to big, which should be bs but lets try):
Number of entries expected in End Of Central Directory does not correspond to number of entries in Central Directory.
when uploading a random xlsx file:
Offset to Central Directory cannot be held in an Int64.
I do not know what is going on, it might have something to do with the way postman serializes the xlsx file and the way my debug session (on a windows machine) deserializes it which is different from the way AWS-Lambda deserializes it but that's just a complete guess.
I always get a 400 - Bad Request response
I'm at a loss and am hoping someone here knows what to do.
This is the method in my controller, however the problem occurs before this:
[HttpPost("productmodel")]
public async Task<IActionResult> SeedProductModel()
{
try
{
_logger.LogInformation("Starting seed product model");
var memoryStream = new MemoryStream();
_logger.LogInformation($"request body: {Request.Body}");
Request.Body.CopyTo(memoryStream);
var command = new SeedProductModelCommand(memoryStream);
var result = await _mediator.Send(command);
if (!result.Success)
{
return BadRequest(result.MissingProducts);
}
return Ok();
}
catch (Exception ex)
{
_logger.LogError(ex.Message);
return BadRequest();
}
}
postman:
we do not use api keys for our test environment
Since you are uploading binary content to API Gateway, you need to enable it through the console.
Go to API Gateway -> select your API -> Settings -> Binary Media Types -> application/octet-stream, like the image below
Save it and make sure to redeploy your API, otherwise your changes will have no effect.
To do so, select your API -> Actions -> Deploy API

Running a jar file in bluemix, inside a dialog app

I'm currently trying to create an application like a Virtual Agent, using Watson Dialog. I have to use Node.js with this Watson service, but I have never used it before, so I took my time.
For now, I can use Java to call the dialog service to simulate an user. But I want to use Node.js to call Java to simulate the Agent.
In Watson Dialog, the Agent has a number of sentences written in a file like dialog.xml. But instead I want my Agent to ask specific questions according to the user's profile.
That's why I'm using a BRMS tool, written in Java. I created a .jar and want to call it in /public/demo.js to fill the variable response:
var texts = dialog.conversation.response;
var response = texts.join('<br/>');
I tried this in /public/demo.js:
var exec = require('child_process').exec;
var child = exec('java -jar C:\\PATH\\Example.jar',
function (error, stdout, stderr){
response += stdout;
if(error !== null){
console.log("Error -> "+error);
}
});
Using that code in another application, it works without any problem, I can run my .jar. I'm sure of it. But once written in my Bluemix app, the first line make it crash. Am I missing something in the manifest.yml file? Do I need to change a config? Or maybe it comes from the demo.js file?
Thank you for helping.

Upload functionality (BrowserStack using node.js)

I have a test for uploading a file (code below) in my application and testing it locally works perfectly. However, when I test it using BrowserStack, BrowserStack cannot access the file in my local machine.
I have checked their documentation about using BrowserStack with Node.js but I haven't seen any documentation about upload functionality. My question is, how do I tell BrowserStack to access my local file?
Has anyone encountered the same issue before?
this.selectJmxFile = function(jmxFilePath, done){
this.driver.findElement(webdriver.By.xpath("//input[#type='file']")).sendKeys(jmxFilePath);
this.driver.wait(function () {
return driver.isElementPresent(webdriver.By.css('.test.files.msg.right'));
}, this.timeout).then(function () {
driver.findElement(webdriver.By.css('.test.files.msg.right')).getText().then(function(text) {
expect(text).to.equal('1 new file(s) selected');
done();
});
});
};
where jmxFilePath is set as:
this.jmxFile = process.cwd() + '/test/functional/features/data/test.jmx';
Thanks!
Ok as it turns out this isn't supported yet as this has only been added in selenium v2.45.0 in Node.js. BrowserStack will have this functionality once they support the latest version of selenium. Guess I have to find another workaround!
You need to set the file detector and it would be transported to remote Browser Stack machine on which test is running -
webDriver.setFileDetector(new LocalFileDetector());

With Nodejs, why can I read from one Azure blob container but not from another?

I have a nodejs app running as a Worker Role in Azure Cloud Services where I have two blob storage containers that the app will read from when responding to certain user requests.
Here's my setup:
Using the azure-storage package to interface with my blob storage.
Two containers, each holding files of different types that the user may ask for at some point.
And I use the following code to stream the files to the HTTP response:
exports.getBlobToStream = function(containerName, fileName, res) {
var blobService = azure.createBlobService();
blobService.getBlobProperties(containerName, fileName, function(error, properties, status){
if(error || !status.isSuccessful)
{
res.header('Content-Type', "text/plain");
res.status(404).send("File " + fileName + " not found");
}
else
{
res.header('Content-Type', properties.contentType);
res.header('Content-Disposition', 'attachment; filename=' + fileName);
blobService.createReadStream(containerName, fileName).pipe(res);
}
});
};
One important
In the past I've had no issues reading from either container. In my research on the problemI've found an identical (but outdated) issue on the all-encompassing azure-sdk-for-node here https://github.com/Azure/azure-sdk-for-node/issues/434. The solution that fixed that problem also fixed mine, but I can't understand why. Particularly when I can read from the other container from within the same app and using the same code without any issues.
I can live with the solution but want to understand what's going on. Any thoughts or suggestions?
#winsome, thanks for raising this issue to us. If you set EMULATED, it means the code will call the local storage emulator other than the real storage account and expected to fail. Regarding the one container works under EMULATED, a guess is your local storage emulator also has a same container. Please check.

Resources