TypeError: Method get TypedArray.prototype.length called on incompatible receiver [object Object] or indefinite hang when trying to modify requestParams.body
See original GitHub issueI’m trying to upload a file via a PUT request with no luck. As far as I can tell this is the way that it is being done in artillery-plugin-http-file-uploads. I suspect the TypeError is coming from when either artillery or request is trying to calculate the length of the request body. Is this a known issue? Has anyone been able to successfully upload a file using artillery?
artillery-plugin-http-file-uploads/index.js:
traverse(requestParams).forEach(function(o) {
if (o && o.fromFile) {
const filename = path.resolve(
basePath,
renderVariables(o.fromFile, userContext.vars));
debug(`Updating`, o, `with`, filename);
const stream = fs.createReadStream(filename);
// in-place update:
this.update(stream);
}
});
app.ts:
import { config } from "./config";
import * as artillery from "./node_modules/artillery/lib/commands/run";
import * as fs from "fs";
import * as temp from "tmp";
let script = {
"config": {
"target": "http://" + config.get("pasUrl") + ":" + config.get("pasPort"),
"phases": [
{
"duration": 1,
"arrivalCount": 1
}
],
"processor": "../scenarios/scenario1.js",
"mode": "uniform"
},
"scenarios": [
{
"flow": [
{
"post": {
"url": "/ViewingSession",
"headers": {
"Content-Type": "application/json"
},
"beforeRequest": "setRequestBodyForViewingSessionPost",
"capture": {
"json": "$.viewingSessionId",
"as": "viewingSessionId"
}
}
},
{
"put": {
"url": "/ViewingSession/u{{ viewingSessionId }}/SourceFile",
"headers": {
"Accusoft-Secret": "mysecretkey",
"Content-Type": "application/octet-stream"
},
"beforeRequest": "setRequestBodyForViewingSessionPut",
}
}
]
}
]
};
let tempfile = temp.fileSync({ "dir": "temp" });
fs.writeFileSync(tempfile.name, JSON.stringify(script, undefined, 4), { "flag": "w" });
// artillery(filename, options)
artillery(tempfile.name, {});
scenario1.ts:
export function setRequestBodyForViewingSessionPut(requestParams, context, ee, next) {
requestParams.body = fs.createReadStream(path.join(__dirname, "..", "documents", "creating-wireframes.pdf"));
return next(); // Artillery hangs indefinetly
}
export function setRequestBodyForViewingSessionPut2(requestParams, context, ee, next) {
let readStream = fs.createReadStream(path.join(__dirname, "..", "documents", "creating-wireframes.pdf"));
let bufferArray = [];
readStream.on("data", function(data) {
bufferArray.push(data);
});
readStream.on("close", function() {
requestParams.body = Buffer.concat(bufferArray);
return next(); // TypeError: Method get TypedArray.prototype.length called on incompatible receiver [object Object]
});
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
TypeError: Method Uint8Array.length called on incompatible ...
TypeError : Method Uint8Array.length called on incompatible receiver [object Object] at Buffer.get length (native) at writeFd (fs.js:1207:45) ...
Read more >TypeError: Method get TypedArray.prototype.length called on ...
TypeError : Method get TypedArray.prototype.length called on incompatible receiver.
Read more >JavaScript TypeError - X.prototype.y called on incompatible type
This JavaScript exception called on incompatible target (or object)” occurs if a function (on a given object), is called with a 'this' ...
Read more >X.prototype.y called on incompatible type - Javascript MDN 文档
The JavaScript exception "called on incompatible target (or object)" occurs when a ... TypeError: Method Set.prototype.add called on incompatible receiver ...
Read more >notebookffad25d0e2 - Kaggle
Copy & Edit 47. arrow_drop_up ... [\\]^_`{|}~\t\n\r', lower=True, split=" ") tokenizer.fit_on_texts(train['Body']) train_x ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@brianjenkins94 file uploads are known to work well. There’s a DIY solution here: https://github.com/shoreditch-ops/artillery/issues/320#issuecomment-329448748. If you need a solution which just works out of the box, and also works when running distributed tests from AWS, check out Artillery Pro.
"artillery": "^1.6.0-19"