Base64 not working with long strings #530
-
I am trying to encode my svg to base64 but i am getting that error: I am using the same svg that @PatrickAlphaC sir used but still getting this error. First i tried it on hardhat network and didn't get anything back for my tokenURI. Then i tried this on Remix IDE for encoding and got this error in return. I also copied the base64.sol in a seperate file on remix. But when i am using small string values like " hello " then it is giving me the encoded string.please help |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
Can you add the line that is erroring? |
Beta Was this translation helpful? Give feedback.
-
code: pragma solidity ^0.8.0; contract hashString{ here function svgToImageURI is giving this problem |
Beta Was this translation helpful? Give feedback.
-
Maybe its the SVG your entering. Also use double quotes "" instead of '' single quotes when imputing it in ur function on remix Try:
//SPDX-License-Identifier: MIT
pragma solidity 0.8.7;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Base64.sol";
contract Test {
function svgToImageURI(string memory svg)
public
pure
returns (string memory)
{
string memory baseURL = "data:image/svg+xml;base64,";
string memory svgBase64Encoded = Base64.encode(
bytes(string(abi.encodePacked(svg)))
);
return string(abi.encodePacked(baseURL, svgBase64Encoded));
}
} |
Beta Was this translation helpful? Give feedback.
Maybe its the SVG your entering.
Also use double quotes "" instead of '' single quotes when imputing it in ur function on remix
Try: