在客户端从DB渲染图像

时间:2017-01-19 20:58:44

标签: javascript mongodb express mongoose

使用express / mongo我可以将图像(现在是PNG)保存到我的本地数据库。

我能够以这种格式返回它:

[{"_id":"588121e1e819315079dd57b3","username":"default user","description":"default description","location":"london, default","__v":0,"timestamp":"2017-01-19T20:30:25.361Z","image":{"data":{"type":"Buffer","data":[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,2,158,0,0,1,44,8,2,0,0,0,229,254,36,39,0,0,27,73,73,68,65,84,120,218,237,221,249,123,83,101,222,128,241,249,31,164,11,45,165,80,232,66,105,75,75,55,232,190,87,68,118,4,134,29,97,16,21,68,180,138,160,162,20,81,112,128,65,1,135,22,148,101,216,188,94,217,4,198,65,70,24,113,192,113,4,149,151,85,180,101,95,154,54,73,147,46,233,238,251,244,13,182,33,221,146,182,161,57,207,185,63,215,247,7,47,69,172,205,73,111,158,147,115,158,243,135,223,0,0,128,68,254,192,183,0,0,0,210,14,0,0,72,59,0,0,32,237,0,0,128,180,3,0,64,218,1,0,0,105,7,0,0,164,29,0,0,144,118,0,0,64,218,1,0,32,237,0,0,128,180,3,0,0,210,14,0,0,72,59,0,0,32,237,0,0,144,118,0,0,64,218,1,0,0,105,7,0,0,164,29,0,0,144,118,0,0,72,59,0,0,32,237,0,0,128,180,3,0,0,210,14,0,0,72,59,0,0,164,29,0,0,144,118,0,0,64,218,1,0,0,105,7,0,0,164,29,0,0,210,14,0,0,72,59,0,0,32,237,0,0,128,180,3,0,0,210,14,0,0,105,7,0,0,164,29,0,0,144,118,0,0,64,218,1,0,32,237,0,0,128,180,3,0,0,210,14,0,0,72,59,0,0,32,237,0,0,144,118,0,0,64,218,1,0,0,105,7,0,0,164,29,0,0,144,118,0,0,72,59,0,0,32,237,0,0,128,180,3,0,0,210,14,0,0,72,59,0,0,164,29,0,0,144,118,0,0,64,218,1,0,0,105,7,0,0,164,29,0,0,210,14,0,0,72,59,0,0,32,237,0,164,165,209,104,78,158,60,153,155,155,179,112,225,171,147,39,79,76,75,75,9,13,13,241,246,246,114,113,121,172,97,220,220,92,252,253,253,6,13,138,122,242,201,161,115,230,204,94,190,252,157,79,63,221,115,238,220,185,202,202,74,190,129,0,105,7,208,245,242,243,243,183,110,221,50,107,214,204,176,176,80,203,132,219,59,30,30,238,153,153,233,175,191,190,248,232,209,163,165,165,165,124,99,1,210,14,224,145,58,123,246,108,118,246,210,232,232,200,142,228,188,149,204,143,27,247,148,248,19,131,86,91,196,183,26,32,237,0,28,168,168,168,232,195,15,63,136,141,29,236,136,162,55,157,238,221,221,166,76,153,44,214,241,181,181,181,124,243,1,210,14,160,51,93,185,114,101,222,188,185,158,158,221,31,77,212,173,38,34,98,96,78,206,70,78,212,3,164,29,64,39,184,116,233,226,244,233,211,92,93,187,117,73,212,45,199,207,207,247,131,15,214,150,151,151,243,162,0,164,29,64,123,220,187,119,111,254,252,23,220,220,92,186,60,234,150,19,20,20,248,183,191,109,231,20,61,64,218,1,216,161,186,186,122,227,198,191,246,238,237,237,84,81,183,156,140,140,180,115,231,206,241,74,129,180,3,64,219,174,94,189,154,150,150,226,180,81,183,188,69,62,59,123,41,55,196,131,180,3,64,139,234,234,234,114,115,115,186,234,90,185,246,77,66,66,252,149,43,151,121,237,64,218,1,192,154,193,96,152,49,99,186,130,162,222,48,61,123,246,248,244,211,61,188,130,32,237,0,208,40,63,63,127,240,224,104,37,118,189,97,22,47,94,84,83,83,195,75,9,210,14,0,191,157,62,125,218,207,175,175,162,187,110,158,9,19,198,151,149,149,241,130,130,180,3,80,181,163,71,143,122,121,121,74,208,117,243,100,102,166,235,116,58,94,86,144,118,0,42,181,122,245,42,101,93,52,103,203,196,199,199,21,21,177,249,60,72,59,0,85,118,61,41,41,33,32,192,79,178,180,155,235,174,215,235,121,137,65,218,1,168,200,250,245,235,68,215,197,196,199,199,186,187,187,202,87,247,204,204,12,182,164,5,105,7,160,22,185,185,57,230,174,155,39,40,40,80,190,180,139,153,50,101,18,215,204,131,180,3,144,223,174,93,59,45,187,46,38,33,33,78,202,133,187,152,37,75,222,228,21,7,105,7,32,179,125,251,246,89,117,93,238,133,187,152,253,251,247,241,186,131,180,3,144,211,158,61,187,155,237,186,121,225,238,108,79,120,235,172,241,246,246,202,207,207,231,213,7,105,7,32,155,157,59,119,180,212,117,243,72,121,169,124,195,99,226,170,171,171,57,6,64,218,1,168,168,235,98,98,99,7,187,186,118,147,181,238,171,86,253,153,195,0,164,29,128,36,182,110,221,210,102,215,205,211,167,79,111,89,211,238,233,217,253,151,95,126,225,96,0,105,7,160,120,57,57,27,109,236,186,152,168,168,8,89,211,46,102,244,232,145,28,15,32,237,0,84,212,117,243,244,232,225,33,113,221,255,254,247,35,28,21,32,237,0,20,169,174,174,110,227,198,191,218,219,117,185,239,130,19,19,29,29,201,245,116,32,237,0,20,217,245,53,107,86,183,163,235,98,226,226,98,36,190,152,78,204,238,221,187,56,66,64,218,1,168,165,235,210,95,76,39,38,50,50,188,182,182,150,227,4,164,29,128,90,186,46,38,60,60,76,226,180,139,57,114,228,48,135,10,72,59,0,5,16,139,209,229,203,223,233,96,215,197,36,38,198,203,186,165,188,121,134,15,127,146,163,5,164,29,128,2,186,190,108,89,118,199,187,110,30,63,191,190,114,47,220,175,94,189,202,49,3,210,14,64,45,93,23,19,17,49,80,238,180,191,253,246,91,28,54,32,237,0,156,84,117,117,213,91,111,45,233,196,174,171,225,156,124,104,104,72,93,93,29,7,15,72,59,0,103,236,250,226,197,175,117,110,215,205,211,183,175,143,220,11,247,51,103,190,231,248,1,105,7,160,150,174,139,9,11,27,32,119,218,179,179,151,114,8,129,180,3,112,34,21,21,166,69,139,28,213,117,49,241,241,177,114,167,61,41,38,172,174,210,192,129,4,210,14,192,89,186,190,96,193,124,199,117,221,60,61,123,246,144,187,238,55,183,197,155,190,201,170,206,255,188,174,66,199,65,5,210,14,64,242,174,139,9,12,12,144,59,237,7,150,132,149,126,150,80,63,123,147,76,95,191,88,149,119,160,206,84,200,1,6,210,14,224,145,50,153,30,81,215,213,112,11,220,146,201,254,15,210,222,56,137,166,127,61,95,245,235,222,186,242,2,14,54,144,118,0,14,87,90,90,58,103,206,51,143,166,235,98,18,18,226,228,126,84,204,152,68,239,38,105,111,156,242,227,115,170,174,238,169,43,187,199,129,7,210,14,64,134,174,171,225,227,246,96,63,247,86,210,222,216,248,127,206,170,186,178,163,182,244,14,7,33,72,59,0,101,119,93,76,64,128,159,220,231,228,53,59,227,108,169,251,131,198,127,57,173,234,210,214,90,227,13,14,72,144,118,0,29,162,215,235,103,205,122,250,209,119,93,13,119,183,255,184,46,218,246,180,55,54,254,232,148,202,11,155,107,139,243,56,56,65,218,1,180,167,235,51,102,76,235,146,174,139,25,60,56,90,238,180,31,94,58,176,29,105,111,108,252,63,38,85,158,223,88,171,187,194,129,10,210,14,64,1,93,55,143,155,155,139,196,105,223,241,106,72,71,210,222,48,101,95,76,168,60,183,161,86,123,241,183,223,216,154,30,164,29,64,11,52,26,205,244,233,93,220,117,233,175,164,91,255,124,255,78,73,123,99,227,143,140,173,252,105,93,77,225,185,223,234,106,57,134,65,218,1,60,212,245,137,19,39,116,121,215,197,248,250,246,145,56,237,239,206,232,215,185,105,111,108,252,225,81,149,63,174,173,209,156,165,241,32,237,0,156,168,235,98,130,130,2,37,78,251,59,211,3,28,148,246,198,198,31,26,94,241,195,170,154,130,239,127,171,173,230,216,6,105,7,212,232,254,253,251,206,211,117,49,225,225,97,18,167,125,233,200,96,221,159,51,173,70,191,234,241,226,213,67,90,155,53,79,148,29,124,189,250,198,87,53,119,78,218,49,133,63,113,120,131,180,3,170,115,251,246,237,177,99,71,59,79,215,165,191,72,254,237,20,143,162,23,123,219,49,11,124,140,219,230,85,223,185,196,177,10,210,14,64,145,93,55,111,55,43,113,218,87,100,120,216,21,245,154,123,87,57,80,65,218,1,40,184,235,230,113,119,119,149,53,237,27,134,122,182,29,245,151,250,232,182,206,55,92,191,80,90,90,90,89,89,89,91,203,101,113,32,237,0,218,146,151,151,55,114,228,112,231,236,186,24,47,47,79,105,239,107,31,221,163,181,168,191,236,171,219,190,64,68,221,248,48,209,248,138,138,10,26,15,210,14,160,197,174,143,24,49,204,105,187,46,166,87,175,158,178,166,253,203,73,61,91,140,250,206,87,12,183,126,54,182,202,220,248,154,154,26,14,99,144,118,0,138,233,186,152,190,125,125,100,77,251,133,217,222,214,81,207,10,208,127,250,70,155,81,167,241,32,237,0,154,113,233,210,197,225,195,159,116,242,174,139,241,247,247,149,178,235,158,110,143,105,230,55,137,250,157,124,99,7,148,148,148,208,120,144,118,64,189,93,127,226,137,33,206,223,117,49,129,129,1,82,166,61,222,207,245,65,212,95,13,212,239,93,102,188,127,211,216,121,104,60,72,59,64,215,157,119,250,247,239,39,101,218,103,70,185,23,189,22,220,233,81,111,218,120,147,201,84,93,205,86,116,32,237,128,188,206,157,59,167,160,174,139,9,14,238,47,101,218,215,205,31,95,82,120,183,180,93,204,181,182,11,43,120,144,118,64,78,63,252,112,54,51,51,93,65,93,23,19,18,18,36,101,218,79,157,58,213,142,85,120,121,121,57,183,189,129,180,3,80,112,215,197,132,134,134,200,215,117,31,159,94,122,189,158,168,131,180,3,104,191,51,103,206,40,177,235,178,174,218,39,77,154,104,123,212,77,38,19,81,7,105,7,240,144,83,167,254,157,150,150,162,196,174,203,250,89,251,230,205,155,136,58,72,59,0,53,118,93,202,180,187,185,185,92,187,118,141,168,131,180,3,80,99,215,197,4,5,5,74,150,246,17,35,134,183,18,117,246,135,7,105,7,208,162,99,199,190,84,122,215,165,220,178,102,251,246,237,45,69,189,174,174,142,227,22,164,29,64,139,93,79,78,78,82,122,215,229,219,104,214,199,167,151,70,163,105,186,115,28,81,7,105,7,160,138,174,203,247,120,152,69,139,94,35,234,32,237,0,236,115,248,240,33,105,186,46,166,119,111,111,105,186,238,238,238,122,249,242,229,134,251,212,137,58,72,59,128,182,29,56,112,64,154,168,155,167,71,15,15,105,210,254,204,51,179,27,150,236,236,252,10,210,14,64,141,93,23,227,230,230,34,205,146,253,252,249,243,13,167,226,57,92,65,218,1,180,97,239,222,189,242,117,61,62,62,86,154,37,251,220,185,207,89,238,26,203,17,11,210,14,160,53,59,119,238,144,175,235,98,162,163,35,229,232,186,183,183,87,126,126,126,67,218,171,170,170,56,104,65,218,1,168,174,235,98,194,194,6,200,145,246,213,171,87,89,222,240,198,5,116,32,237,0,212,216,117,49,253,250,249,75,208,245,196,196,4,203,231,188,149,149,149,113,220,130,180,3,104,94,110,110,142,196,93,151,227,206,55,119,119,215,111,191,61,109,185,100,231,108,60,72,59,128,230,229,228,108,148,187,235,98,60,60,220,149,158,246,247,223,95,105,181,247,28,135,46,72,59,0,149,118,93,130,203,227,71,140,24,94,92,92,108,181,81,60,71,47,72,59,128,135,212,213,213,125,248,225,7,210,119,93,76,120,120,152,162,187,30,18,18,116,253,250,117,171,103,192,240,84,55,144,118,0,214,93,95,179,102,181,26,186,46,38,32,192,79,185,93,247,242,242,60,125,250,84,211,167,176,115,12,131,180,3,80,105,215,197,136,58,42,180,235,110,110,46,251,247,239,111,250,216,86,150,236,32,237,0,26,137,42,172,90,245,190,122,186,158,144,16,231,234,218,77,161,105,207,205,205,105,218,117,150,236,32,237,0,30,234,250,178,101,217,234,233,186,152,129,3,67,21,218,245,13,27,214,55,237,122,73,73,9,219,212,128,180,3,80,111,215,197,248,250,246,81,98,215,215,175,95,103,108,78,101,101,37,71,50,72,59,0,245,118,61,49,49,222,221,221,85,97,91,211,184,62,182,101,254,236,102,187,94,90,90,202,145,12,210,14,160,94,117,117,213,226,197,175,169,173,235,98,34,35,195,149,213,117,31,247,110,7,7,251,234,63,223,211,108,218,121,52,59,72,59,0,85,119,93,140,191,191,175,130,186,30,213,195,237,187,4,127,77,70,255,226,175,191,228,84,60,72,59,0,186,174,236,179,241,83,253,60,175,167,5,138,174,139,49,92,248,201,170,235,60,9,6,164,29,64,189,138,10,83,86,214,203,234,236,186,130,30,228,218,203,173,91,110,132,143,57,234,230,49,106,10,184,42,30,164,29,64,51,93,95,176,96,190,106,187,46,102,197,224,192,126,30,46,78,222,245,209,125,60,206,37,5,88,118,189,112,76,44,31,177,131,180,3,160,235,214,51,54,57,174,32,163,127,94,106,224,11,129,94,238,174,206,24,245,96,79,215,29,81,125,44,163,110,158,162,231,198,90,118,189,186,186,154,227,25,164,29,80,187,210,210,82,149,119,93,76,78,106,68,67,44,191,75,240,31,223,215,195,169,46,131,127,111,64,175,155,191,127,178,110,53,218,229,89,60,145,29,164,29,192,67,93,159,51,231,25,149,119,125,72,82,252,181,140,32,171,100,158,136,243,235,242,192,251,118,119,201,14,241,206,75,237,215,108,212,205,163,219,254,17,93,7,105,7,64,215,31,154,213,169,145,45,133,243,187,68,255,249,129,94,222,110,143,122,87,249,24,47,183,13,3,123,223,104,97,165,110,57,197,39,190,224,86,55,144,118,0,116,189,113,82,147,18,174,164,7,183,158,79,145,216,77,17,62,195,125,186,187,57,184,232,254,221,93,230,245,243,250,42,206,175,205,162,55,140,33,239,106,121,121,57,199,51,72,59,160,118,122,189,126,198,140,105,116,93,204,210,148,104,219,59,250,75,106,191,156,112,159,73,190,158,125,221,93,58,119,141,254,114,255,158,71,98,124,239,165,247,183,253,139,105,184,60,158,83,241,32,237,0,93,167,235,141,75,246,139,109,45,217,155,157,251,25,253,191,137,247,95,63,176,247,51,1,61,146,188,221,123,218,121,198,62,216,211,117,100,31,143,69,65,61,119,71,247,185,156,210,175,29,95,192,131,203,227,23,206,226,170,120,144,118,128,174,211,245,198,121,47,53,170,221,89,181,156,130,140,254,23,146,251,29,139,245,219,30,217,103,221,192,222,203,7,244,122,43,216,59,171,127,207,151,2,189,22,7,245,20,127,253,126,104,175,220,8,159,189,131,250,158,78,240,191,110,195,39,232,54,142,110,243,26,145,246,218,218,90,14,108,144,118,64,165,52,26,205,212,169,147,41,122,195,133,241,191,180,107,201,238,60,99,222,61,158,189,231,64,218,1,245,118,125,226,196,9,20,189,97,54,91,220,203,174,200,121,60,216,168,41,40,41,41,225,216,6,105,7,232,58,147,240,199,228,216,59,77,238,101,87,214,20,61,63,142,39,193,128,180,3,42,117,247,238,29,186,110,53,95,165,133,42,123,201,158,209,95,247,209,10,145,118,147,201,196,17,14,210,14,168,203,237,219,183,199,142,29,77,203,45,231,77,123,110,120,115,222,15,218,79,29,103,179,26,144,118,128,174,51,9,35,146,227,242,20,126,42,190,126,70,68,26,245,58,238,124,3,105,7,212,229,214,173,91,116,189,233,28,74,11,147,96,201,174,93,50,215,188,117,60,119,190,129,180,3,106,145,151,151,55,98,196,48,66,110,53,111,75,113,42,94,140,254,224,110,209,117,46,143,7,105,7,212,226,216,177,99,143,63,158,65,200,173,102,124,114,236,13,9,78,197,139,25,18,98,184,123,91,164,157,221,227,65,218,1,181,116,61,49,49,158,144,91,77,90,82,194,127,210,7,200,177,100,47,122,245,105,243,217,248,138,138,10,14,120,144,118,64,114,251,246,237,75,72,136,35,228,77,231,111,105,225,114,116,189,254,108,252,231,123,204,105,231,26,58,144,118,64,254,174,179,94,151,248,110,183,7,51,52,212,120,255,174,57,237,108,49,11,210,14,208,117,53,206,204,228,152,59,114,124,196,110,190,54,126,233,139,230,174,179,15,29,72,59,32,179,93,187,118,210,245,102,103,84,114,220,207,10,127,6,140,245,78,53,255,254,138,15,218,65,218,1,201,109,219,182,149,207,215,91,122,182,219,127,101,185,116,206,60,133,147,82,141,134,98,115,218,107,106,106,56,248,65,218,1,186,174,162,73,77,74,248,82,249,27,197,91,239,27,191,117,157,185,235,220,209,14,210,14,200,105,203,150,79,232,122,179,147,156,148,176,63,109,160,100,93,215,12,13,53,220,190,105,78,59,119,180,131,180,3,18,90,183,238,67,62,95,111,105,118,72,116,171,91,227,5,116,239,189,106,252,93,85,85,21,111,1,144,118,128,174,171,101,114,83,35,228,235,122,253,5,116,231,206,52,164,157,219,222,64,218,1,186,78,215,37,217,129,142,179,241,32,237,128,108,150,47,127,135,174,183,52,91,82,195,165,236,122,253,146,253,63,39,57,27,15,144,118,72,217,245,101,244,187,165,235,230,118,165,73,219,245,162,249,147,140,22,56,27,15,210,14,208,117,249,31,253,114,80,138,167,176,183,185,77,13,103,227,65,218,1,121,188,249,230,27,36,188,165,125,105,190,78,15,149,184,235,69,47,79,179,92,178,179,83,13,72,59,32,131,133,11,95,37,225,205,206,83,201,113,63,166,135,72,220,245,250,37,251,15,255,105,232,122,105,105,41,111,7,144,118,128,174,75,59,207,38,15,206,147,232,185,47,205,223,203,254,230,243,150,75,246,202,202,74,222,17,32,237,128,178,189,242,74,22,9,111,118,86,164,70,221,149,58,234,15,182,159,251,229,50,23,208,1,164,29,242,120,238,185,103,73,120,211,201,76,138,255,76,190,77,100,155,221,49,126,227,74,203,174,155,76,38,222,20,32,237,0,93,151,109,166,37,199,74,255,225,250,131,135,188,77,72,52,22,22,88,166,189,182,182,150,247,5,72,59,64,215,165,154,149,169,81,119,100,255,112,189,97,244,71,15,88,118,157,123,222,0,210,14,5,155,49,99,26,21,183,154,49,201,113,39,210,66,85,18,245,250,27,222,22,63,99,124,24,247,188,1,164,29,74,245,210,75,47,178,143,172,213,54,115,43,82,163,110,168,102,177,94,63,35,34,13,215,126,181,236,122,89,89,25,111,13,128,180,67,145,178,179,151,186,184,60,230,233,217,61,44,108,0,81,23,51,61,57,230,84,250,0,21,69,221,124,42,254,179,109,44,217,1,210,14,197,171,171,171,123,227,141,215,69,215,27,198,203,203,83,4,94,181,43,248,97,73,241,59,211,194,11,84,22,245,250,83,241,11,103,25,13,6,150,236,0,105,135,226,187,158,149,245,178,101,215,27,70,172,224,7,12,8,78,72,136,83,79,212,211,147,226,215,166,70,94,83,213,25,248,134,171,226,199,196,24,110,228,179,100,7,72,59,164,237,122,195,184,187,187,246,235,231,31,27,59,88,238,168,167,38,37,188,155,18,245,115,122,176,10,163,254,224,84,252,177,67,86,93,231,194,120,128,180,67,97,196,130,44,43,235,165,214,187,222,48,174,174,221,124,124,122,133,135,135,201,119,150,126,72,82,252,234,212,200,75,42,142,122,253,158,178,127,121,203,216,4,247,178,3,164,29,10,235,250,156,57,179,109,236,186,229,116,239,238,22,16,224,55,104,80,148,28,207,119,217,146,26,126,67,149,167,223,31,250,136,253,185,177,70,157,214,170,235,21,21,21,188,77,0,210,14,249,187,110,117,169,93,80,80,96,76,204,32,37,158,123,127,37,101,208,225,180,176,251,234,46,250,131,143,216,71,13,50,228,93,181,234,122,73,73,9,59,198,3,164,29,234,234,186,85,227,3,3,3,162,163,35,157,63,234,51,146,99,182,165,134,255,154,17,76,209,31,76,102,112,241,55,255,108,122,42,190,186,186,154,119,10,64,218,161,12,149,149,149,83,166,76,238,196,174,91,157,171,247,245,237,19,26,26,18,23,23,227,84,107,244,231,83,6,111,73,13,63,175,142,237,223,237,187,116,110,207,199,77,187,206,213,115,0,105,135,146,186,62,121,242,68,7,117,189,97,98,123,186,125,20,222,251,187,212,224,221,105,3,223,74,137,254,99,114,108,151,236,34,55,53,57,246,221,148,168,131,105,97,215,84,255,81,122,139,151,206,253,249,245,166,93,231,84,60,64,218,65,215,127,191,71,206,245,177,169,126,158,95,196,248,54,77,200,245,140,160,227,105,161,31,167,70,44,73,137,126,58,57,38,51,41,222,17,45,31,159,28,251,74,202,160,117,169,145,255,32,231,182,92,58,247,202,211,77,47,157,19,170,170,170,120,179,0,164,29,10,80,94,94,62,126,252,56,7,69,61,208,195,229,237,16,239,139,201,253,108,239,202,165,244,224,19,105,161,255,147,54,240,163,212,136,236,148,232,5,41,131,254,148,28,35,218,60,164,213,234,167,252,255,62,113,19,146,99,103,38,199,100,165,12,90,145,26,181,57,53,226,64,90,216,183,233,3,110,209,114,187,186,62,103,140,81,83,192,169,120,128,180,67,193,93,31,53,106,132,35,162,254,120,239,238,219,34,251,220,77,239,228,240,220,203,232,47,150,221,191,164,7,95,76,15,190,154,30,44,254,90,12,183,168,117,218,37,241,83,51,12,183,111,114,42,30,32,237,160,235,141,211,179,103,143,185,147,198,127,147,66,107,21,216,245,9,73,134,171,151,141,205,225,170,120,128,180,67,1,196,207,235,206,237,122,120,248,192,181,107,255,114,235,214,45,241,59,23,159,248,66,51,100,0,177,84,90,215,47,53,219,117,54,168,1,72,59,20,192,96,48,100,102,166,119,74,209,93,93,187,141,27,247,212,161,67,159,23,23,23,91,246,160,248,171,35,212,93,57,79,127,137,53,92,185,208,108,215,121,188,27,64,218,161,162,174,247,237,235,179,104,209,107,23,47,54,159,132,7,117,127,34,148,112,42,96,189,126,241,167,102,95,193,146,146,18,246,138,7,72,59,84,209,245,196,196,248,205,155,55,21,20,20,24,219,82,124,234,184,102,120,4,249,116,234,235,230,126,189,210,210,203,199,71,236,0,105,135,179,43,42,42,74,76,76,232,200,142,114,51,102,76,63,113,226,184,209,30,197,103,191,45,28,19,67,68,157,177,235,179,134,25,110,94,107,233,133,171,172,172,228,45,3,144,118,56,123,215,227,227,227,218,23,245,160,160,192,229,203,223,201,203,203,51,182,139,225,194,143,133,127,76,38,165,206,117,255,250,188,9,198,251,119,91,122,201,76,38,19,111,25,128,180,67,206,174,15,29,58,100,207,158,61,122,189,222,216,49,134,235,249,69,115,198,16,84,103,217,71,118,217,2,163,86,219,210,139,197,238,52,0,105,135,179,187,115,231,78,92,92,140,189,183,167,191,240,194,188,239,191,255,222,216,137,10,53,218,37,115,201,106,151,143,238,147,181,70,131,161,165,87,169,172,172,140,221,105,0,210,14,103,239,122,100,100,184,237,81,143,136,24,248,193,7,107,197,191,101,116,4,131,65,183,113,37,113,237,178,121,114,160,254,139,125,173,188,62,165,165,165,116,29,32,237,144,164,235,174,174,221,38,76,24,119,248,240,33,67,203,235,57,91,148,148,148,148,151,151,183,254,107,244,95,30,212,140,136,34,180,143,252,98,248,204,226,255,61,219,250,107,199,173,110,0,105,135,83,187,121,243,134,45,93,247,245,237,179,120,241,162,139,23,47,118,112,65,46,22,124,149,149,149,230,53,95,117,117,117,27,171,247,171,151,11,103,143,36,183,143,238,195,245,37,115,141,5,247,232,58,64,218,161,96,249,249,249,33,33,65,109,221,158,158,240,201,39,31,107,52,154,14,70,93,44,211,155,222,0,221,102,221,141,218,34,237,251,139,137,174,195,103,200,0,253,238,77,109,158,107,161,235,0,105,135,130,187,238,225,225,62,107,214,204,175,191,254,87,7,139,46,122,80,81,81,209,74,18,218,174,251,255,159,156,47,28,19,75,128,29,117,18,126,230,176,214,79,194,211,117,128,180,67,217,93,23,127,127,245,234,85,55,110,220,232,248,185,247,170,170,42,91,174,183,170,169,169,17,229,104,227,228,252,173,27,69,175,63,75,134,59,121,50,131,117,27,222,109,229,14,183,134,151,146,174,3,164,29,78,237,210,165,139,1,1,126,77,163,62,114,228,240,67,135,62,23,61,22,63,202,59,120,238,93,212,218,174,47,201,150,186,215,47,223,15,238,214,140,140,38,201,157,118,197,220,127,191,177,229,143,104,92,15,15,144,118,56,123,215,253,253,31,234,186,183,183,87,86,214,203,87,174,92,22,255,84,252,16,111,119,215,69,155,27,46,145,107,7,177,46,180,165,238,134,155,215,181,203,22,16,230,14,205,19,161,186,220,213,70,109,81,155,223,109,238,95,7,72,59,20,214,245,65,131,162,114,114,54,138,159,224,230,127,218,238,174,139,0,116,202,51,66,196,23,32,126,43,155,246,156,63,117,188,112,250,16,34,221,158,189,99,95,158,214,210,179,89,217,71,22,32,237,80,152,179,103,207,154,187,238,230,230,50,101,202,164,19,39,142,91,46,200,218,209,117,177,200,22,63,253,59,247,83,88,241,101,180,121,203,251,239,23,207,107,117,219,214,115,239,187,29,103,224,39,167,233,191,216,107,227,139,203,115,95,0,210,14,231,239,250,25,31,159,94,126,126,190,217,217,75,111,222,188,209,52,168,118,117,221,242,246,116,71,168,168,168,176,117,231,186,59,55,181,107,223,214,12,25,64,185,91,139,250,168,65,186,29,27,141,58,173,141,223,85,158,211,10,144,118,40,160,235,163,71,143,220,189,123,151,72,102,179,11,101,219,187,222,236,237,233,142,32,254,43,182,124,244,222,176,185,141,118,233,124,77,102,16,21,183,158,161,97,186,245,239,26,238,221,181,253,15,109,92,12,15,144,118,40,192,207,63,255,220,210,63,18,63,199,109,233,122,155,183,167,59,130,141,95,91,99,224,47,157,211,102,191,168,121,60,152,162,215,207,176,8,221,71,43,12,55,175,219,117,107,3,23,205,1,164,29,202,102,203,69,233,230,219,211,187,240,139,52,153,76,246,61,92,230,234,37,237,123,11,213,124,138,190,112,84,180,110,243,26,195,157,91,118,125,223,248,112,29,32,237,144,191,235,162,169,246,222,158,238,32,118,157,156,127,16,248,27,249,186,77,171,11,199,37,168,43,234,79,63,169,255,108,155,177,176,192,222,205,133,56,9,15,144,118,200,220,245,14,222,158,238,32,118,92,57,111,73,167,213,31,249,172,104,238,120,217,119,128,15,209,190,241,108,241,169,227,70,251,159,200,215,236,229,23,0,72,59,36,233,122,103,221,158,238,56,85,85,85,246,46,223,31,44,226,47,159,215,109,92,89,56,33,73,182,101,250,236,145,186,93,185,118,125,160,110,185,88,119,146,179,50,0,105,7,58,185,235,142,184,61,221,161,203,119,123,63,125,183,40,124,113,241,191,191,210,174,88,88,56,38,70,217,69,159,146,81,127,221,123,91,207,116,97,177,14,144,118,168,174,235,142,190,61,221,113,196,114,179,67,27,221,23,23,23,127,251,47,237,218,165,133,19,83,20,182,70,223,252,23,195,249,31,58,178,195,127,89,89,25,159,172,3,164,29,146,176,124,4,203,35,187,61,221,161,196,159,75,218,119,126,222,234,150,57,253,158,143,139,94,159,227,156,27,219,21,78,72,212,46,207,210,31,250,212,112,61,175,227,207,226,99,47,26,128,180,67,182,174,119,201,237,233,14,85,87,87,103,251,214,117,109,47,229,207,126,171,223,189,73,155,253,98,225,212,140,46,124,208,106,225,159,70,104,223,95,172,223,191,195,112,249,124,167,252,159,153,47,141,228,93,0,144,118,72,213,245,178,178,178,174,189,61,221,161,196,31,86,218,115,253,124,91,91,216,22,159,60,166,219,181,73,187,114,81,209,188,9,142,123,152,108,225,184,248,162,151,166,106,215,190,173,255,108,91,241,119,39,237,189,117,205,150,143,213,217,136,6,32,237,144,176,124,42,249,223,108,255,21,118,54,198,254,167,239,245,255,60,172,223,179,89,183,225,93,237,242,172,162,69,179,139,230,142,47,156,62,164,240,169,184,250,246,15,143,176,46,183,248,155,35,163,11,199,39,22,206,28,86,52,127,146,246,141,103,181,43,22,234,54,174,172,175,248,215,71,13,23,127,50,22,220,119,208,87,107,62,67,67,212,1,210,14,16,120,197,35,234,0,105,7,36,100,254,12,190,227,23,217,41,139,121,87,96,162,14,144,118,64,102,34,117,101,101,101,210,71,189,188,188,156,253,103,0,210,14,168,72,109,109,173,148,139,120,229,238,76,0,144,118,0,157,67,44,109,77,38,147,210,27,47,138,46,217,77,140,0,105,7,208,9,141,87,220,58,222,188,70,167,232,0,105,7,208,26,81,74,209,203,242,242,114,231,204,188,121,135,127,46,142,3,72,59,128,118,46,229,69,230,69,74,59,180,65,125,103,172,206,205,57,103,129,14,144,118,0,157,70,172,146,171,171,171,205,165,47,43,43,115,220,154,94,252,206,226,247,175,168,168,16,45,23,127,182,96,117,14,144,118,0,143,46,246,34,189,230,222,139,18,139,228,151,151,151,139,42,139,69,118,201,239,154,102,219,76,252,26,241,43,197,175,23,255,150,185,226,226,247,17,139,114,66,14,144,118,0,0,64,218,1,0,0,105,7,0,0,164,29,0,0,144,118,0,0,72,59,0,0,32,237,0,0,128,180,3,0,0,210,14,0,0,72,59,0,0,164,29,0,0,144,118,0,0,64,218,1,0,0,105,7,0,0,164,29,0,0,210,14,0,0,72,59,0,0,32,237,0,0,128,180,3,0,0,210,14,0,0,105,7,0,0,164,29,0,0,144,118,0,0,64,218,1,0,32,237,0,0,128,180,3,0,0,210,14,0,0,72,59,0,0,32,237,0,0,144,118,0,0,64,218,1,0,0,105,7,0,0,164,29,0,0,144,118,0,0,72,59,0,0,32,237,0,0,128,180,3,0,0,210,14,0,0,72,59,0,0,164,29,0,0,144,118,0,0,64,218,1,0,0,105,7,0,0,164,29,0,0,210,14,0,0,72,59,0,0,32,237,0,0,128,180,3,0,0,210,14,0,0,105,7,0,0,164,29,0,0,144,118,0,0,208,126,255,7,239,250,83,70,199,75,64,250,0,0,0,0,73,69,78,68,174,66,96,130]},"contentType":"image/png"}}]

在API方面,我正在使用直接的查找...

  api.get('/getSample', (req, res) => {
    Image.find({}, (err, doc) => {
      console.log('returned image(s)', doc);
      // res.contentType(doc.data.contentType);
      // res.send(doc.data);
      res.send(doc);
    });
  });

如何在客户端使用此结果并在图像标记中呈现图像?我如何使用我在这里得到的图像数据格式(我假设缓冲数据数组是我需要注意的)

感谢。

1 个答案:

答案 0 :(得分:1)

使用额外的encode函数找到here,以下是将图像对象转换为图像的简单示例:

function createImage (record) {
  var oImg=document.createElement("img");
  oImg.setAttribute('src', 'data:'+record.image.contentType+';base64,'+encode(record.image.data.data));
  return oImg;
}

function encode (input) {
  var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  var output = "";
  var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
  var i = 0;

  while (i < input.length) {
    chr1 = input[i++];
    chr2 = i < input.length ? input[i++] : Number.NaN; // Not sure if the index 
    chr3 = i < input.length ? input[i++] : Number.NaN; // checks are needed here

    enc1 = chr1 >> 2;
    enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
    enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
    enc4 = chr3 & 63;

    if (isNaN(chr2)) {
        enc3 = enc4 = 64;
    } else if (isNaN(chr3)) {
        enc4 = 64;
    }
    output += keyStr.charAt(enc1) + keyStr.charAt(enc2) +
              keyStr.charAt(enc3) + keyStr.charAt(enc4);
  }
  return output;
}

以下是如何将其与数据结合使用的示例:

var data = [{
  "_id": "588121e1e819315079dd57b3",
  "username": "default user",
  "description": "default description",
  "location": "london, default",
  "__v": 0,
  "timestamp": "2017-01-19T20:30:25.361Z",
  "image": {
    "data": {
        "type": "Buffer",
        "data": [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 2, 158, 0, 0, 1, 44, 8, 2, 0, 0, 0, 229, 254, 36, 39, 0, 0, 27, 73, 73, 68, 65, 84, 120, ... 0, 105, 7, 0, 0, 164, 29, 0, 0, 144, 118, 0, 0, 208, 126, 255, 7, 239, 250, 83, 70, 199, 75, 64, 250, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130]
    },
    "contentType": "image/png"
  }
}];

document.body.appendChild(createImage(data[0]));