Jump to content


Photo
Question

How to change account Avatar?

node.js node-steam-user

  • Please log in to reply
3 replies to this topic

#1 Zorenko

Zorenko

    Member

  • Member
  • PipPip
  • 11 posts

Posted 15 April 2019 - 08:17 AM

I have code

SteamCommunity.prototype.uploadAvatar = function(image, format, callback) {
	if(typeof format === 'function') {
		callback = format;
		format = null;
	}

	// are we logged in?
	if (!this.steamID) {
		callback(new Error("Not Logged In"));
		return;
	}

	var self = this;

	if(image instanceof Buffer) {
		doUpload(image);
	} else if(image.match(/^https?:\/\//)) {
		this.httpRequestGet({
			"uri": image,
			"encoding": null
		}, function(err, response, body) {
			if(err || response.statusCode != 200) {
				if(callback) {
					callback(err ? new Error(err.message + " downloading image") : new Error("HTTP error " + response.statusCode + " downloading image"));
				}

				return;
			}

			if(!format) {
				format = response.headers['content-type'];
			}

			doUpload(body);
		}, "steamcommunity");
	} else {
		if(!format) {
			format = image.match(/\.([^\.]+)$/);
			if(format) {
				format = format[1];
			}
		}

		FS.readFile(image, function(err, file) {
			if(err) {
				if(callback) {
					callback(err);
				}

				return;
			}

			doUpload(file);
		})
	}

	function doUpload(buffer) {
		if(!format) {
			if(callback) {
				callback(new Error("Unknown image format"));
			}

			return;
		}

		if(format.match(/^image\//)) {
			format = format.substring(6);
		}

		var filename = '';
		var contentType = '';

		switch(format.toLowerCase()) {
			case 'jpg':
			case 'jpeg':
				filename = 'avatar.jpg';
				contentType = 'image/jpeg';
				break;

			case 'png':
				filename = 'avatar.png';
				contentType = 'image/png';
				break;

			case 'gif':
				filename = 'avatar.gif';
				contentType = 'image/gif';
				break;

			default:
				if(callback) {
					callback(new Error("Unknown or invalid image format"));
				}

				return;
		}

		self.httpRequestPost({
			"uri": "https://steamcommunity.com/actions/FileUploader",
			"formData": {
				"MAX_FILE_SIZE": buffer.length,
				"type": "player_avatar_image",
				"sId": self.steamID.getSteamID64(),
				"sessionid": self.getSessionID(),
				"doSub": 1,
				"json": 1,
				"avatar": {
					"value": buffer,
					"options": {
						"filename": filename,
						"contentType": contentType
					}
				}
			},
			"json": true
		}, function(err, response, body) {
			if(err) {
				if(callback) {
					callback(err);
				}

				return;
			}

			if(body && !body.success && body.message) {
				if(callback) {
					callback(new Error(body.message));
				}

				return;
			}

			if(response.statusCode != 200) {
				if(callback) {
					callback(new Error("HTTP error " + response.statusCode));
				}

				return;
			}

			if(!body || !body.success) {
				if(callback) {
					callback(new Error("Malformed response"));
				}

				return;
			}

			if(callback) {
				callback(null, body.images.full);
			}
		}, "steamcommunity");
	}
};

How to choose a photo and upload it?



#2 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 2,042 posts

Posted 15 April 2019 - 01:03 PM

Read the docs, please.



#3 Zorenko

Zorenko

    Member

  • Member
  • PipPip
  • 11 posts

Posted 15 April 2019 - 01:47 PM

steam.login(logOnOptions, function(err, sessionID, cookies, steamguard) {
	if (err) {
		console.log("[Bot] There was an error logging in! Error details: " + err.message);
		process.exit(1); //terminates program
	} else {
		console.log("[Bot] Successfully logged in as " + logOnOptions.accountName);
		steam.chatLogon();
		community.uploadAvatar('https://trinixy.ru/pics5/20180508/uncommon_01.jpg');
		manager.setCookies(cookies, function(err) {
			if (err) {
				console.log(err);
				process.exit(1);
			}
		});
	}
	steam.startConfirmationChecker(20000, identitySecret); //Auto-confirmation enabled!
});

Error:

C:\Users\a\Desktop\d>node Donation-Bot.js
[Bot] Successfully logged in as john200214
C:\Users\a\node_modules\steamcommunity\components\profile.js:254
                callback(new Error("Not Logged In"));
                ^

TypeError: callback is not a function
    at SteamCommunity.uploadAvatar (C:\Users\a\node_modules\steamcommunity\components\profile.js:254:3)
    at C:\Users\a\Desktop\d\Donation-Bot.js:29:13
    at SteamCommunity.<anonymous> (C:\Users\a\node_modules\steamcommunity\index.js:202:5)
    at Request._callback (C:\Users\a\node_modules\steamcommunity\components\http.js:67:15)
    at Request.self.callback (C:\Users\a\node_modules\request\request.js:185:22)
    at Request.emit (events.js:189:13)
    at Request.<anonymous> (C:\Users\a\node_modules\request\request.js:1161:10)
    at Request.emit (events.js:189:13)
    at Gunzip.<anonymous> (C:\Users\a\node_modules\request\request.js:1083:12)
    at Object.onceWrapper (events.js:277:13)

C:\Users\a\Desktop\d>pause

Edited by Zorenko, 15 April 2019 - 01:49 PM.

  • Zorenko likes this

#4 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 2,042 posts

Posted 15 April 2019 - 02:13 PM

You probably want to use steam.uploadAvatar and not community.uploadAvatar. Also, attach a callback. Also also, don't use the auto-confirmation checker.


  • Zorenko likes this





Also tagged with one or more of these keywords: Question, node.js, node-steam-user

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users