Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // create new product
- app.post('/newproduct', upload.single('images'), function (req, res) {
- if (req.body.title == '' || req.body.price == '') {
- res.json({success: false, msg: 'Please add title and price.'});
- console.log('title: ' + req.body.title);
- console.log('price: ' + req.body.price);
- } else {
- var newProduct = new Product({
- title: req.body.title,
- price: req.body.price,
- description: req.body.description,
- images: req.file
- });
- console.log(req.body);
- console.log(req.file);
- // save the new product
- newProduct.save(function(err) {
- if (err) {
- res.json({success: false, msg: 'Listing was unsuccessful.'});
- } else {
- res.json({success: true, msg: 'Successful creating a new product!'});
- console.log(newProduct.createdAt);
- console.log(newProduct.updatedAt);
- }
- });
- }
- });
- { title: 'TEST', description: 'Test 2', price: '350' }
- { fieldname: 'images',
- originalname: 'fileName.png',
- encoding: '7bit',
- mimetype: 'image/png',
- destination: 'public/uploads/',
- filename: '4ce97ccc379e4c29404392417c4fbfb6',
- path: 'public/uploads/4ce97ccc379e4c29404392417c4fbfb6',
- size: 7063823 }
- POST /newproduct 200 72.025 ms - 51
- func web() {
- Alamofire.request(.GET, postEndPoint, parameters: nil, encoding:
- .JSON).responseJSON { (response:Response<AnyObject, NSError>) -> Void in
- print(response.result.value)
- if (response.result.value != nil)
- {
- self.arr = (response.result.value) as! NSMutableArray
- let descriptor: NSSortDescriptor = NSSortDescriptor(key: "createdAt", ascending: false)
- self.arr.sortedArrayUsingDescriptors([descriptor])
- }
- self.homeTableView.reloadData()
- self.homeCollectionView.reloadData()
- }
- }
- func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
- let cell: MainTableViewCell = tableView.dequeueReusableCellWithIdentifier("MainTableViewCell", forIndexPath: indexPath) as! MainTableViewCell
- let dict = arr[indexPath.row] as! NSDictionary
- print(dict)
- print(dict["title"])
- cell.productTitleLabel?.text = String (dict["title"]! )
- cell.productDescriptionLabel?.text = String (dict["description"]! )
- cell.productPriceLabel?.text = String (dict["price"]! )
- cell.productTimeLabel?.text = String (dict["createdAt"]!)
- // how can I upload image file
- cell.frame.size.width = screenWidth / 3
- return cell
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement