Created
June 10, 2014 11:46
-
-
Save AbeHaruhiko/cf66796040f1a4feeccd to your computer and use it in GitHub Desktop.
MongoDBに画像を保存してnode.js(Express)とangularJSで表示する ref: http://qiita.com/AbeHaruhiko/items/e38eb90982bb289af246
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.book.read = function(req, res) { | |
Book.find({ title: 'とある本' }, function(err, docs) { | |
if (err) throw new Error(err); | |
res.send(docs); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String stringifyBitmap(Bitmap bitmap) { | |
ByteArrayOutputStream byteArrayBitmapStream = new ByteArrayOutputStream(); | |
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayBitmapStream); | |
return Base64.encodeToString(byteArrayBitmapStream.toByteArray(), Base64.DEFAULT); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String stringifyBitmap(Bitmap bitmap) { | |
ByteArrayOutputStream byteArrayBitmapStream = new ByteArrayOutputStream(); | |
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayBitmapStream); | |
return Base64.encodeToString(byteArrayBitmapStream.toByteArray(), Base64.DEFAULT); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
jsondata: { | |
title: 'とある本', | |
coverImage: <BASE64エンコード済みの文字列> | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img src="data:image/gif;base64,{{book.coverImage}}"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('angularApp').controller('MainCtrl', function ($scope, $http) { | |
var url = '/book'; | |
$scope.book = []; | |
$scope.getBook = function() { | |
$http.get(url).success(function(data) { | |
$scope.book = data; | |
}); | |
}; | |
$scope.getBook(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bookスキーマを定義 | |
var BookSchema = new mongoose.Schema({ | |
title : String, | |
coverImage : String | |
}); | |
exports.Book = db.model('Book', BookSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/book', db.book.read); // GETの処理。要認証 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment